When I update parent scope variable from custom directive by calling a function from directive then directive dom is not updated. In this example $scope.ascending is true, and sort() function do toggle its value. I am calling sort function from both parent view as well as from child(directive), but change is not reflected in directive template. run this code as is to see the issue
HTML
<html ng-app="sortApp">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>
<script src="testApp.js"></script>
</head>
<body>
<div ng-view>
<div ng-controller="sortController">
<span>Parent scope: sorting order: </span>"{{ascending ? 'a->z' : 'z->a'}}"
<br /><br />
<div><input type='button' value='toggal sort order from parent' ng-click='sort()' /></div><br/>
<sorting-from-directive asc="ascending" sort-action="sort()"> </sorting-from-directive>
</div>
</div>
</body>
</html>
CODE
var app = angular.module('sortApp', []);
app.controller('sortController', function ($scope) {
$scope.ascending = true;
$scope.sort = function () {
$scope.ascending = !$scope.ascending;
}
});
app.directive('sortingFromDirective', function () {
return {
restrict: 'EA',
scope: {
asc: '=',
sortAction: '&'
},
template: "<div><input type='button' value='toggal sort order from directive' ng-click='sortAction()'/> <span>Child scope: sorting order:</span><span ng-show={{asc}}>a->z</span> <span ng-hide={{asc}}>z->a</span></div>"
};
});