Javascript Ng模型不适用于动态添加的html控件
我正在尝试预选具有相同ng模型的选项,但当我在$scope.alertConditions.rows中添加项目时,不会基于ng模型预选选项。感谢您的帮助 HTML:Javascript Ng模型不适用于动态添加的html控件,javascript,angularjs,angularjs-ng-repeat,angular-ngmodel,Javascript,Angularjs,Angularjs Ng Repeat,Angular Ngmodel,我正在尝试预选具有相同ng模型的选项,但当我在$scope.alertConditions.rows中添加项目时,不会基于ng模型预选选项。感谢您的帮助 HTML: 提前感谢。如果您希望预选项目,则必须以这种方式使用“选择”。 使用“ng选项”而不是“ng重复” 像这样: scope.listColor = [{name:"blue"}, {name:"red"}]; //Reference the first item in the list // So, the selected ite
提前感谢。如果您希望预选项目,则必须以这种方式使用“选择”。 使用“ng选项”而不是“ng重复” 像这样:
scope.listColor = [{name:"blue"}, {name:"red"}];
//Reference the first item in the list
// So, the selected item will be, the first element (blue)
scope.modelColor = scope.listColor[0];
希望对您有帮助;)谢谢,ng选项非常有效。您能告诉我在选项中使用ng repeat有什么问题吗?我不太清楚:p但要将模型与列表中选定的元素绑定,您必须使用ng选项。ng repeat有效,但在select中第一个元素将为空
$scope.alertConditions = {
run_alert: 0,
run_date: null,
measure: 'M0002',
attribute: null,
rows:[{
attribute_member: null,
count_of_period: null,
operator: 1,
type: 1,
value: '',
format: 1
}]
}
$scope.addRow = function(){
$scope.alertConditions.rows.push({
attribute_member: null,
count_of_period: null,
operator: 1,
type: 1,
value: '',
format: 1
});
}
<select ng-model="modelColor" ng-options="color.name for color in listColor">
</select>
scope.listColor = [{name:"blue"}, {name:"red"}];
//Reference the first item in the list
// So, the selected item will be, the first element (blue)
scope.modelColor = scope.listColor[0];