In the cases when you execute any server and your attempts to load a new page view and then your codes in directive gets loaded before your services are updated so you can using $rootScope.
This is an example of above case
View
<service-history log="log" data-ng-repeat="log in requiedData"></service-history>
Controller
app.controller("MyController",['$scope','$rootScope', function($scope, $rootScope) {
$scope.$on('$viewContentLoaded', function () {
SomeSerive.getHistory().then(function(data) {
$scope.requiedData = data;
$rootScope.$broadcast("history-updation");
});
});
}]);
Directive
app.directive("serviceHistory", function() {
return {
restrict: 'E',
replace: true,
scope: {
log: '='
},
link: function($scope, element, attrs) {
function updateHistory() {
if(log) {
//do something
}
}
$rootScope.$on("history-updation", updateHistory);
}
};
});
0 Comment(s)