Neel Sinha
Neel Sinha

Reputation: 5

How to use $scope variable in ng-init

I have a $scope variable in controller and I want to access it in DOM in ng-init.

In controller -

 $scope.value=true; 

I want to check or unchecked checkbox based on $scope.value variable. For this I m doing this :

   <input type="checkbox" ng-model="val" ng-init="val={{value}}">abc

but this isn't working...Any solution to this?

Upvotes: 0

Views: 3210

Answers (3)

pradeep1991singh
pradeep1991singh

Reputation: 8365

You can just assign value in ng-init

<input type="checkbox" ng-model="val" ng-init="val=value">

For more information: angualr ngInit directive

See working fiddle

Upvotes: 0

Sherin
Sherin

Reputation: 185

you can use

<input type="checkbox" ng-model="val" ng-init="val=value">abc

hope it helps

Upvotes: 0

Amaranadh Meda
Amaranadh Meda

Reputation: 724

First make sure that you are gave the root dom element in the view as ng-controller="controllerName" then try this

  <input type="checkbox" ng-model="val" ng-init="val=value">abc

Try this

Upvotes: 1

Related Questions