Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ng模型不适用于动态添加的html控件_Javascript_Angularjs_Angularjs Ng Repeat_Angular Ngmodel - Fatal编程技术网

Javascript 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模型的选项,但当我在$scope.alertConditions.rows中添加项目时,不会基于ng模型预选选项。感谢您的帮助

HTML:


提前感谢。

如果您希望预选项目,则必须以这种方式使用“选择”。 使用“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];