javascript - $watch a variable for change angularjs -
i'm new complex angular directives. have variable in rootscope called $root.page
. have set watch so:
$scope.$watch( "$root.page", function handlechange( newvalue, oldvalue ) { //show select page on page change console.log(oldvalue, newvalue); if (!oldvalue || oldvalue !== newvalue) { $scope.showselectonly = true; } } );
the way code structured, $scope.showselectonly
true. want $scope.showselectonly
true when there change $root.page
, want false in other cases (i.e. when there no change $root.page
variable).
i don't think need watch case. might want using angular value instead. have access angular value in entire angular module app. that, can update showselectonly when page changed.
angular.module('myapp', []) .value('page', true) .value('showselectonly', true);
you can inject page controller in module, , update both values needed.
angular.module('myapp') .controller('myctrl', function (page, showselectonly) { if (!page) { showselectonly = true; } });
Comments
Post a Comment