我試圖創建一個按鈕來保存複選框選擇的選項,然後清除每個對象的「選定」值。角度按鈕來保存選定的選項
angular.module('app', []).controller('FormController', ['$scope', function($scope){
$scope.goals = [{
name: 'flex',
descrip: "Increase Flexibility",
selec: false,
submit: ''
},
{
name: 'build',
descrip: "Build Muscle",
selec: false,
submit: ''
},
{
name: 'cardio',
descrip: "Improve Cardio",
selec: false,
submit: ''
},
{
name: 'lose',
descrip: "Lose Weight",
selec: false,
submit: ''
}
];
$scope.submitGoals = function(){
forEach($scope.goals, function(goal, key){
$scope.goal.submit = $scope.goals.selec;
$scope.goal.selec = '';
});
};
}]);
HTML:
<body ng-controller='FormController'>
<div class='container col-md-6 col-md-offset-6 panel' >
<form>
<span ng-repeat='goal in goals'>
<input type='checkbox' value='{{goal.name}}' name=selectedGoal[] ng-model='goal.selec'>{{goal.descrip}}
</span>
<input type='button' ng-model='submitGoals()' value='Submit'>
</form>
</div>
<pre>
You want to:
<p ng-repeat='goal in goals' ng-show='goal.selec'>{{goal.descrip}}<br></p>
<div class='panel-submit'>
You selected: <p ng-repeat='goal in goals' ng-show'goal.submit'>{{goal.submit}}</p>
</div>
</pre>
</body>
這submitGoals功能不適用於保存值的工作,因爲{{goal.submit}}在HTML表達仍爲空白。
建議你研究一些教程這樣的事情,如果你有它的背景。這不是一個教程服務或代碼寫作服務 – charlietfl