I am trying to simplify my controller. So I tried to set variable to populate my checkbox list from outside controller. Is it possible?
Here is my current code http://ift.tt/2gSgJa0
VIEW HTML
<div ng-controller="AdminEventsCtrl">
<h1>Array 1</h1>
<ul>
<li ng-repeat="item in array1">
<input type="checkbox" ng-model="formData.value1[item.value]" value="" />
</li>
</ul>
<h1>Array 2</h1>
<script>
array2 = [{
text: 'Option 1',
value: 'opt1'
}, {
text: 'Option 2',
value: 'opt2'
}, {
text: 'Option 3',
value: 'opt3'
}, {
text: 'Option 4',
value: 'opt4'
}];
</script>
<ul>
<li ng-repeat="item in array2">
<input type="checkbox" ng-model="formData.value1[item.value]" value="" />
</li>
</ul>
<pre>Array1= </pre>
<pre>Array2= </pre>
</div>
SCRIPT JS
var myApp = angular.module('myApp', []);
function AdminEventsCtrl($scope) {
$scope.formData = {};
$scope.array1 = [{
text: 'Option 1',
value: 'opt1'
}, {
text: 'Option 2',
value: 'opt2'
}, {
text: 'Option 3',
value: 'opt3'
}, {
text: 'Option 4',
value: 'opt4'
}];
}
Aucun commentaire:
Enregistrer un commentaire