简体   繁体   中英

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?

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

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

you can use

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

hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM