Angular structure de base
by Zineb ERRAHMOUNI
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div data-ng-controller="myctrl as ctrl1">
<input type="text" ng-model="ctrl1.taskLabel" />
<button ng-click="ctrl1.addTask()" >Ajouter</button>
<hr/>
Liste des taches :
<ul>
<li ng-repeat="t in ctrl1.tasks">
<input type="checkbox" ng-model="t.done" />
{{ t.label }}
</li>
</ul>
<hr/>
{{ ctrl1.tasks | json }}
</div>
JavaScript
"use strict";
(function() {
var controller = function () {
var mc = this;
mc.tasks=[];
mc.key = 0;
mc.addTask = function() {
if (mc.taskLabel !== null && mc.taskLabel !== '') {
var task = {key : mc.key, label : mc.taskLabel, done : false}
mc.tasks.push(task);
mc.taskLabel='';
mc.key ++;
}
};
};
angular.module("myApp", []);
angular.module("myApp").controller('myctrl', 'controller');
})();