【发布时间】:2015-04-15 11:06:53
【问题描述】:
是否可以在同一个下拉列表中同时使用 ng-bind-html 和 ng-model?在我的应用程序中,我有一个使用 ng-bind-html 填充的选择下拉列表(工作正常),但是当我尝试使用 ng-model 将下拉列表的值绑定到 $scope 时,它不会更新范围使用下拉列表的值,它与我的控制器中的原始声明保持相同。这是它的样子:
<select id="newNumOfPlayers" ng-bind-html="compiledSelect" ng-model="newNumOfPlayers"></select>
我在控制器的开头声明我的变量
$scope.newNumOfPlayers = 0;
这里是我填充选择字符串的地方
$scope.compiledSelect = "";
var contentSelectString = "";
for (i = 1; i <= data[0].noOfPlayersNeeded; i++) {
contentSelectString += "<option value="+i+">"+i+"</option>";
}
$scope.compiledSelect = $sce.trustAsHtml(contentSelectString);
但这总是记录为 0
console.log("new number "+$scope.newNumOfPlayers);
有人有什么想法吗?谢谢
【问题讨论】:
-
您能否解释一下您的流程应该如何工作,以便我们使用
ng-options提出更好的方法,因为如果没有这些,您将不得不编写一个新指令来监视您动态生成的@ 987654326@ 所以它会传播到你的模型中。我特别感兴趣data、data[0].noOfPlayersNeeded和newNumOfPlayersNeeded的相关性。
标签: angularjs select angularjs-scope angular-ngmodel