$Watch not working while watch text scope variable from the controller. But scope is available for function call like "ng-blur", why not for $watch. What is wrong with my flow. Can anyone give suggestion
Html
<div ng-include="'html/bar.html'" ng-controller="barController"></div>
<div class="content-container view" data-ui-view>
</div>
bar.html
<li data-ng-repeat="menu in menuData.menus" data-ng-init="menu.showSubMenu = false">
<a class="main-menu" data-ng-click="menu.showSubMenu = !menu.showSubMenu">{{menu.menuName}}</a>
<div data-ng-show="menu.showSubMenu && menu.subMenus" class="top-nav-menu-wrapper" style="display: block;">
<div class="menu-container">
<div class="drop-down-menu" style="display: block; top:10px;">
<div class="container-left" data-equalizer="">
<ul>
Menus li
</ul></div></div></div></div></li>
barController
$scope.$watch('menu.showSubMenu', function(newValue, oldValue) {
console.log(newValue);
if (newValue !== oldValue) {
// stuff
}
});
also tried this
$scope.$watchCollection('menu', function(newValue, oldValue) {
console.log(newValue);
if (newValue !== oldValue) {
// stuff
}
});
I gave context html only for understand scenario. here I need to access "menu.showSubMenu" variable from controller also update from controller while click on window to close sub menu
I tried this and working fine