我是angular.I的新手,我正在做一个简单的演示,其中我将根据当前选定的值添加新的选择。我很喜欢选项和模型的动态价值。我无法获得选定的值,请帮助。获取角度js中的选定值
HTML代码放在这里:
<md-input-container ng-repeat="a in selects" class="md-block" style="margin-top:20px;">
<label>{{a.label}}</label>
<md-select required ng-model="a.model" ng-change="callme()" flex="40">
<md-option ng-model="a.model" ng-repeat="optionValue in a.options" ng-value="optionValue.option">
{{optionValue.option}}
</md-option>
</md-select>
<div class="errors" ng-messages="petApp.favoriteColor.$error">
<div ng-message="required"> You need to select a option</div>
</div>
</md-input-container>
JS代码到这里
$scope.selects = [{label:"Your Pet",model:"pet",options:[{option:"Cat"},{option:"Dog"},{option:"Guinea pig"}]}];
$scope.callme = function(){
console.log($scope.pet);
$scope.selects.push({label:"Your Pet",model:"pet",options:[{option:"Cat"},{option:"Dog"},{option:"Guinea pig"}]});
}
这里的型号名称是宠我虽然$ scope.pet这是给不确定的。
好吧,但它。如果我提供一个用于添加多个选择按钮的按钮,该怎么办?在这种情况下,我需要定义多个模型。那该怎么办呢。 – Madan
@马丹我用你需要的信息编辑了答案。 –
@马丹我回答你的问题了吗? –