【问题标题】: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";
        }
    

    【讨论】:

      猜你喜欢
      • 2016-12-24
      • 2019-08-24
      • 2017-04-25
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      • 2020-06-20
      • 1970-01-01
      • 2016-01-28
      相关资源
      最近更新 更多