Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS ng-style not changing with property
    primarykey
    data
    text
    <p>I cant seem to figure out why the style property is not getting updated. In my larger application it seems to work fine. </p> <pre><code>angular.module('Model', []) .factory('SizeModel', function () { return { width: 200, height: 100, display:"block", getCombined: function() { return parseInt(this.width) + parseInt(this.height); } }; }); function AlbumCtrl($scope,SizeModel) { $scope.master = SizeModel; $scope.$watch("master",function(){ $scope.myprop = { display: $scope.master.display, backgroundColor: "#333", width: $scope.master.width+'px', height: $scope.master.height+'px', color: "#FFF" }; }); } function AnoCtrl($scope,SizeModel) { $scope.master = SizeModel; $scope.toggle = function(){ $scope.master.display = "none"; } } function EditCtrl($scope,SizeModel) { $scope.master = SizeModel; } </code></pre> <p><a href="http://jsfiddle.net/ganarajpr/C2hRa/4/" rel="nofollow noreferrer">http://jsfiddle.net/ganarajpr/C2hRa/4/</a></p> <p>Here is a fiddle which shows the issue I am currently facing. You will notice that the width and height are getting updated in the div when you change the input. But the style itself doesnt seem to be updating. Anyone can tell me what I am doing wrong here? </p> <p>I have tried all the following scenarios </p> <ol> <li>using $scope.$apply.. - Throws an error stating $apply already in progress..</li> <li>$rootScope.$apply - same as above.</li> <li>Setting another variable in a service which is $watched in the other controller. - no change seen.</li> </ol> <p>It would be really cool if someone can get me an answer to this. Also would be really happy if you can tell me why exactly it is not getting updated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload