简体   繁体   中英

I want to print a static variable inside my html using angualrjs

id is a static variable called Benny inside my html. I want to print id on the screen but am getting a blank.

<scheduled-event
              id1 = "Benny"
              event="event"
              ng-repeat="event in $ctrl.adherence.events">

     <h2>{{id1}}</h2>       
</scheduled-event>

To put a static variable on scope, use the ng-init directive:

 <script src="//unpkg.com/angular/angular.js"></script> <body ng-app> <scheduled-event ng-init="id1='Benny'" event="event" ng-repeat="event in [1,2]"> <h2>{{id1}}</h2> </scheduled-event> </body> 

For more information, see AngularJS ng-init Directive API Reference .

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