我正在做一个角度项目,将表格变量传递给不同的控制器。我对角度有点新意见但是在了解了rootcope之后我仍然没有解决这个问题,控制器将数据发送到表单但是for可以将数据发送到控制器,有人可以帮忙。以下是我的代码;
form:
<form ng-submit="start()">
<div class="list card">
<div class="item item-divider">Select Subjects</div>
<label class="item item-input item-select">
<div class="input-label icon icon-left ion-book">
Subject 1
</div>
<select ng-model="sub1">
<option selected>ENGLISH</option>
</select>
</label>
<label class="item item-input item-select">
<div class="input-label">
Subject 2
</div>
<select ng-model="exam.sub2">
<option>MATHEMATICS</option>
<option selected>LITERATURE</option>
<option>ECONOMICS</option>
<option>GOVERNMENT</option>
<option >PHYSICS</option>
<option>COMMERCE</option>
<option>ACCOUNT</option>
<option>GEOGRAPHY</option>
<option>BIOLOGY</option>
<option>CRS</option>
<option >CHEMISTRY</option>
</select>
</label>
Controller:
app.controller('setCtrl', ["$scope", function(c){
c.start = function(){
console.log = c.exam.sub2
};
}]);
提前致谢enter code here
答案 0 :(得分:0)
您缺少的是您的范围中的考试对象。</ p>
app.controller('setCtrl', ["$scope", function(c){
c.exam = {}; // object to hold your form values
c.start = function(){
console.log( c.exam );
};
}]);
您的HTML输入应为
<select ng-model="exam.sub1">
<select ng-model="exam.sub2">