I have a div
<div class="error-text" ng-if="customerIdLength > customerIdMaxLength" ng-init="error='yes'" >Error presented</div>
here ng-if
is working properly.
But
Based on ng-init
value i am disabling a button like this:
<button class="btn btn-success" type="submit" ng-click="submitNumber();" ng-disabled="error=='yes'">Submit</button>
this is not working. If i am putting this ng-init
to some other element which don't have ng-if
then it is working properly. So what is the reason behind?
<!DOCTYPE html>
<html data-ng-app="myApp">
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
</head>
<body data-ng-controller="testController">
<div class="error-text" ng-init="$parent.error='yes'" ng-if="1 > 0">Error presented</div>
<button class="btn btn-success" type="submit" ng-click="submitNumber();" ng-disabled="error=='yes'">Submit</button>
<script>
// Code goes here
angular
.module('myApp', [])
.controller('testController', ['$scope',
function($scope) {
}
])
</script>
</body>
</html>
you need to use $parent to get inner scope inside ng-if.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With