【问题标题】:concatenate string with scope variable inside ng-model将字符串与 ng-model 内的范围变量连接起来
【发布时间】:2016-10-05 12:51:42
【问题描述】:
如何连接字符串和作用域变量并将其分配给 ng-model
有没有办法表达这个
ng-model="'is'+location.placeName+'Checked'"
【问题讨论】:
标签:
angularjs
concatenation
angular-ngmodel
【解决方案1】:
在这种情况下,您可以使用 ng-bind-model 代替 ng-model
ng-bind-model="is{{location.placeName}}Checked"
谢谢
【解决方案2】:
终于在ozkary使用ng-initplunker随机找到了答案
HTML 视图
<input ng-model="isPlaceChecked" ng-init="isPlaceChecked = checkIfPlaceChecked(location.placeName)"
JS 控制器
$scope.checkIfPlaceChecked = function (placeName) {
return "is" + placeName + "Checked";
}