1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Directives</title>
<meta name="description" content="Carousel">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
</head>
<body ng-app="myApp">
<input type="text" ng-model="task">
{{task}}
<select ng-model="order">
<option value="nom">Par nom</option>
<option value="age">Par age</option>
</select>
<div id="users" ng-controller="userCtrl">
<ul ng-model ="users">
<li ng-repeat="user in users | orderBy:order ">
{{user.username}}
</li>
</ul>
</div>
<button id="btn" value="Update scope"></button>
<script>
var myApp = angular.module("myApp",[]);
myApp.controller('userCtrl', function ($scope){
$scope.users= [{"username":"Marc", "age":"15"},
{"username":"John", "age":"35"},{"username":"Jean","age":"24"},{"username":"Thomas","age":"21"}];
var btn = document.getElementById("btn");
btn.addEventListener("click", function () {
$scope.$apply(function (){
$scope.users[$scope.users.length] = {"username":"Doe","age":"21"};
});
});
});
var scope = angular.element(document.getElementById("users")).scope();
console.log(scope.users[0].username);
</script>
</body> |
Partager