我的角度js代碼不解決佔位符,而我試圖讓它在運行時解決。Angular JS:佔位符沒有得到解決
JS代碼:
var message ={s:"hello {{name}}"};
angular.module("myapp",[]).controller("myctrl", function($scope){
var ctrl=this;
$scope.name="david";
$scope.w=message.s;
$scope.call=function(){
//alert(message);
};
});
HTML:
<div ng-app="myapp">
<div ng-controller="myctrl as ctrl">
{{w}}
<input type="text" ng-model="ctrl.name" />
<input type="submit" ng-click="call();" />
</div>
</div>
預期輸出是:您好大衛;
附加小提琴鏈接:https://jsfiddle.net/rakotkar/o46coezd/2/
你必須使用'{{名}}'(插值)只在模板 –