i have created a directive
adocsModule.directive('modalFooter', function (globalService) {
return {
restrict: 'AE',
replace: true,
scope: {
'onSave': '&',
'onClose': '&',
'loading': '='
},
template: '<div class="modal-footer">' +
' <div class="pull-right">' +
'<button type="submit" ui-ladda="loading" class="button-save ladda-button" ng-click="onSave()" data-style="expand-right">' +
'<span class="ladda-label">{{saveText}}</span>' +
'</button>' +
' <button class="button-cancel" ng-click="onClose()">{{cancelText}}</button>' +
' </div> </div>',
link: function (scope, element, attrs, ctrl) {
scope.saveText = attrs.savetext;
scope.cancelText = attrs.canceltext;
}
};
});
to use this
<modal-footer loading="administrator.loading" on-save="administrator.save()" on-close="administrator.cancel()"></modal-footer>
in my controller when i press save i do . administrator.loading = true it shows loading icon but when on callback i do administrator.loading = false it doesnt stop loading icon. it means it doesnt react to change
i have tried to use scope.$watch and attrs.$observe but problem with those it start showing loading icon on start and it doesnt get back in watch :S
Module.controller('AdminstratorController', ['$scope', function ($scope) {
administrator.save = function () {
administrator.loading = true;
var callback = function () {
administrator.loading false;
}
setTimeout(function () {
administratorService.updateAdministrator( callback);
}, 1000);
};
}]);
can some one guide me how can i fix it.
save(ng-click="onSave()") Do you see your controllerssavefunction not getting any arguments?loadingvalue ?$timeoutinstead ofsetTimeout.('AdminstratorController', ['$scope','$timeout', function ($scope, $timeout) {and$timeout(function () {administratorService.updateAdministrator(callback);}, 1000);When you update something insidesetTimeoutangular does not know about it until the next digest cycle happens. If you use$timeoutdigest cycle will happen. Also how does your ajax call look like and why do you need a timeout with 1sec?Are you not using$http?