SagarVimal
SagarVimal

Reputation: 259

AngularJS : How to change the ng-show condition of a span using a java script function

I want to change the ng-show condition using a java script function.

<span id="error1" ng-show="formerror"><font color="red">{{formerror}}</font></span>

I'm able to get the span attr using

var scope4 = angular.element($("#error1"))

Upvotes: 1

Views: 365

Answers (1)

dfsq
dfsq

Reputation: 193261

You can do it, however I doubt this is very good idea to manipulate with internals of the Angular app from outside of it. But it's possible.

You don't need attribute, you just need to access the scope of the element and change formerror property of it. You can do it using scope method of the angular.element. For example:

var $scope = angular.element($("#error1")).scope();
$scope.formerror = 'Fill in required fields.';
$scope.$apply();

Demo: http://plnkr.co/edit/cmiQCgnxbvG4hrGY1c18?p=preview

Upvotes: 1

Related Questions