When I load the view, I would like to run some initialization code in the appropriate controller.
For this, I used the ng-init directive for the main element of my view:
<div ng-init="init()"> blah </div>
and in the controller:
$scope.init = function () { if ($routeParams.Id) {
First question: is this the right way to do this?
Next, I have a problem with the sequence of events occurring. In the view, I have a Save button that uses the ng-disabled directive as such:
<button ng-click="save()" ng-disabled="isClean()">Save</button>
the isClean() function is defined in the controller:
$scope.isClean = function () { return $scope.hasChanges() && !$scope.isSaving; }
As you can see, it uses the $scope.isSaving flag, which was initialized in the init() function.
PROBLEM: when loading a view, the isClean function is called before the init() function, so the isSaving flag is undefined . What can I do to prevent this?
angularjs
Sam Apr 22 '13 at 14:59 2013-04-22 14:59
source share