How to execute Angular Expressions values in Directives values in Angular Js. {{user.name}} is work. But when I use it in Directive ( ng-init ), It wont work.
ng-init="formData.id='{{user.name}}'"
Or any other way?
The ngInit
directive as the name suggest, does initialization tasks, for example if you want to set an user's name and age data, you can do the following:
<div ng-init="user.name='John'; user.age=50">
This is executed before angular starts bootstrapping your app and compiling templates. Expressions surrounded by double curly braces {{ }}
are bindings that tell angular to evaluate an expression and produce output, so if you want to display data previously initialized just add them to your document like this:
<body ng-app>
<div ng-init="user.name='John'; user.age=50">
{{user.name}} is {{user.age}} years old.
</div>
</body>
Check the very basic example here: http://jsfiddle.net/j9Nfd/
Directive expressions are expressions so just use
ng-init="formData.id = user.name"