Différences
Ci-dessous, les différences entre deux révisions de la page.
| slam4:richclient:angularjs:bases [2016/01/20 17:10] – [Hello world modifié] jcheron | slam4:richclient:angularjs:bases [2019/08/31 14:21] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 6: | Ligne 6: | ||
| Installer AngularJS Eclipse Plugin ([[https:// | Installer AngularJS Eclipse Plugin ([[https:// | ||
| - | **Avec PhpStorm :** | + | **Avec PhpStorm |
| voir [[http:// | voir [[http:// | ||
| ===== -- Téléchargement ===== | ===== -- Téléchargement ===== | ||
| Ligne 23: | Ligne 23: | ||
| <sxh html; | <sxh html; | ||
| - | <script src="http://ajax.googleapis.com/ | + | <script src="https://cdnjs.cloudflare.com/ |
| </ | </ | ||
| </ | </ | ||
| - | Quoi qu'en disent certains, il est préférable d' | + | Quoi qu'en disent certains, il est préférable d' |
| ===== -- Premiers pas ===== | ===== -- Premiers pas ===== | ||
| ==== Traditionnel Hello world : ==== | ==== Traditionnel Hello world : ==== | ||
| Ligne 37: | Ligne 37: | ||
| <meta charset=" | <meta charset=" | ||
| < | < | ||
| - | <script src=" | + | <script src=" |
| </ | </ | ||
| < | < | ||
| Ligne 65: | Ligne 65: | ||
| <meta charset=" | <meta charset=" | ||
| < | < | ||
| - | <script src=" | + | <script src=" |
| </ | </ | ||
| < | < | ||
| Ligne 179: | Ligne 179: | ||
| Un contrôleur est défini par un constructeur permettant d' | Un contrôleur est défini par un constructeur permettant d' | ||
| - | |||
| - | Exemple en dehors d'un module : | ||
| - | <sxh html> | ||
| - | <div ng-app="" | ||
| - | |||
| - | Nom : <input type=" | ||
| - | Prénom : <input type=" | ||
| - | <br> | ||
| - | Nom et prénom : {{nomComplet()}} | ||
| - | |||
| - | </ | ||
| - | |||
| - | < | ||
| - | function personneController($scope) { | ||
| - | $scope.prenom = " | ||
| - | $scope.nom = " | ||
| - | $scope.fullName = function() { | ||
| - | return $scope.nom + " " + $scope.prenom; | ||
| - | } | ||
| - | } | ||
| - | </ | ||
| - | </ | ||
| Exemple de contrôleur dans un module : | Exemple de contrôleur dans un module : | ||
| Ligne 229: | Ligne 207: | ||
| voir [[https:// | voir [[https:// | ||
| + | |||
| + | |||
| + | ==== ControllerAs et $scope ==== | ||
| + | L' | ||
| + | |||
| + | <sxh javascript; | ||
| + | var myApp = angular.module(' | ||
| + | |||
| + | myApp.controller(' | ||
| + | this.value=0; | ||
| + | this.carre = function(value) { return value * value; }; | ||
| + | }]); | ||
| + | |||
| + | </ | ||
| + | |||
| + | La vue associée est la suivante : | ||
| + | <sxh html> | ||
| + | < | ||
| + | < | ||
| + | <input type=" | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| ==== -- $scope ==== | ==== -- $scope ==== | ||
| Ligne 254: | Ligne 255: | ||
| </ | </ | ||
| <script | <script | ||
| - | src="http://ajax.googleapis.com/ | + | src="https://cdnjs.cloudflare.com/ |
| <script src=" | <script src=" | ||
| </ | </ | ||
| Ligne 313: | Ligne 314: | ||
| < | < | ||
| <script | <script | ||
| - | src="http://ajax.googleapis.com/ | + | src="https://cdnjs.cloudflare.com/ |
| <script src=" | <script src=" | ||
| </ | </ | ||
| Ligne 322: | Ligne 323: | ||
| </ | </ | ||
| </ | </ | ||
| + | |||
| + | === Utilisation du service ngCookies === | ||
| + | |||
| + | Le service **ngCookie** n'est pas intégré par défaut à angular, il est donc nécessaire d' | ||
| + | <sxh html; | ||
| + | <script src=" | ||
| + | </ | ||
| + | |||
| + | Il faut ensuite intégrer ngCookies en tant que dépendance dans l' | ||
| + | |||
| + | <sxh javascript; | ||
| + | var App = angular.module(' | ||
| + | </ | ||
| + | |||
| + | nbCookies peut ensuite être injecté dans les contrôleur le nécessitant : | ||
| + | |||
| + | <sxh javascript; | ||
| + | app.controller(" | ||
| + | // Retrieving a cookie | ||
| + | var favoriteCookie = $cookies.get(' | ||
| + | // Setting a cookie | ||
| + | $cookies.put(' | ||
| + | }]); | ||
| + | </ | ||
| + | |||
| === Création d'un service === | === Création d'un service === | ||