在制作模板提供数据,NG-模型 [英] Making data templated in available to ng-model
问题描述
使用服务器端的模板和客户端angularjs时,我没能得到angularjs承认我在模板服务器上的值。
When using server-side templating and client-side angularjs, I'm not able to get angularjs to recognize values I've templated in on the server.
例如(或上的jsfiddle ):
<div ng-app>
<div ng-controller="Ctrl">
<textarea ng-model="data" placeholder="Enter a name here">Templated in</textarea>
{{data}}
</div>
</div>
Angularjs将始终以 $ scope.data code>的值替换在文本区域的值(为空)。我要的是
$ scope.data code>的价值采取模板化的,在App引导,然后再从那里继续正常运行。
Angularjs will always replace the value in the text area with the value of $scope.data
(which is null). What I want is for the value of $scope.data
to take on "Templated in", on app bootstrap, then to continue normally from there.
我怎样才能从服务器值模板,然后让客户端价值一旦angularjs模型绑定?
How can I template in from the server a value, then have angularjs model bind that value once on the client?
推荐答案
使用 NG-INIT
<textarea ng-model="data" placeholder="Enter a name here"
ng-init="data='Templated in'"></textarea>
又见<一个href=\"http://stackoverflow.com/questions/10610282/angularjs-value-attribute-on-an-input-text-box-is-ignored-when-there-is-a-ng-m\">AngularJS - 当使用NG-模型上输入文本框Value属性被忽略和结果?
<一href=\"http://stackoverflow.com/questions/12703820/rails-angularjs-loading-values-into-textfields-on-edit\">rails +在编辑 angularjs装载值到文本框
See also AngularJS - Value attribute on an input text box is ignored when there is a ng-model used? and
rails + angularjs loading values into textfields on edit
这篇关于在制作模板提供数据,NG-模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!