Skip to content

Instantly share code, notes, and snippets.

@AndrianD
Created January 20, 2015 20:36
Show Gist options
  • Select an option

  • Save AndrianD/b30644009509adf0ac94 to your computer and use it in GitHub Desktop.

Select an option

Save AndrianD/b30644009509adf0ac94 to your computer and use it in GitHub Desktop.
testController avec AngularJS
<!DOCTYPE html>
<html>
<head lang="fr">
<meta charset="UTF-8">
<title>test du controller</title>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
</head>
<body ng-app="test">
<p ng-controller="testController">
{{ tamtam }}
</p>
<h3>{{ showAll }}</h3>
<div ng-controller="secondController">
{{ bojo }}
</div>
<label>
<input type="text" ng-model="myTest"/> {{ myTest }}
</label>
<div ng-controller="jeRepete">
<p ng-repeat="item in items">
{{ item.nom }}
</p>
</div>
<script type="text/javascript">
// déclaration du module
var app = angular.module('test', []);
//définition d'un premier controlleur avec un $rotScope'
app.controller('testController', [
'$scope', '$rootScope', function ($scope, $rootScope) {
$rootScope.showAll = "Je m'affiche partout";
$scope.tamtam = "ma super route";
}]
);
//définition d'un second controller '
app.controller('secondController', ['$scope', function ($scope) {
$scope.bojo = 'formidable banjo';
}]);
// ng-repeat
app.controller('jeRepete', [ '$scope', function ($scope){
$scope.items = [
{'nom':'toto', 'age':35, 'sexe':'homme'},
{'nom':'tata', 'age':15, 'sexe':'fille'}
]
}]);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment