Angular, première partie
This commit is contained in:
32
javascript/angular/exercices/services-2/.solution/app.js
Normal file
32
javascript/angular/exercices/services-2/.solution/app.js
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Énoncé:
|
||||
* Implémenter le service "myPrompt" qui pose une question et retourne la réponse entrée par l'utilisateur.
|
||||
* Le service devra lui même utiliser le service $window, service "alias" de l'objet Window fourni par Angular et sa méthode
|
||||
* prompt().
|
||||
*
|
||||
* Documentation:
|
||||
* - Service $window: https://code.angularjs.org/1.3.15/docs/api/ng/service/$window
|
||||
* - window.prompt(): https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt
|
||||
*
|
||||
*/
|
||||
|
||||
var Exo = angular.module('Exo', []);
|
||||
|
||||
Exo.controller('MainCtrl', ['$scope', 'myPrompt', function($scope, myPrompt) {
|
||||
|
||||
$scope.question = 'Quel est votre age ?';
|
||||
$scope.response = '--';
|
||||
|
||||
$scope.poserQuestion = function() {
|
||||
$scope.response = myPrompt.ask($scope.question);
|
||||
};
|
||||
|
||||
}]);
|
||||
|
||||
Exo.service('myPrompt', ['$window', function($window) {
|
||||
|
||||
this.ask = function(question) {
|
||||
return $window.prompt(question);
|
||||
};
|
||||
|
||||
}]);
|
21
javascript/angular/exercices/services-2/.solution/index.html
Normal file
21
javascript/angular/exercices/services-2/.solution/index.html
Normal file
@ -0,0 +1,21 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf8">
|
||||
<title>Exercice: création de service</title>
|
||||
</head>
|
||||
<!-- Déclaration de l'application -->
|
||||
<body ng-app="Exo">
|
||||
|
||||
<div ng-controller="MainCtrl">
|
||||
<label>Question</label>
|
||||
<input type="text" ng-model="question" />
|
||||
<button ng-click="poserQuestion()">Poser la question</button>
|
||||
<br /><br />
|
||||
<b>Votre réponse:</b> <span>{{ response }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Import de du framework Angular -->
|
||||
<script src="../../node_modules/angular/angular.js"></script>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -8,7 +8,6 @@
|
||||
* - Service $window: https://code.angularjs.org/1.3.15/docs/api/ng/service/$window
|
||||
* - window.prompt(): https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
var Exo = angular.module('Exo', []);
|
||||
@ -18,6 +17,8 @@ Exo.controller('MainCtrl', ['$scope', /*'myPrompt',*/ function($scope /*,myPromp
|
||||
$scope.question = 'Quel est votre age ?';
|
||||
$scope.response = '--';
|
||||
|
||||
// scope.response = myPrompt.ask($scope.question);
|
||||
$scope.poserQuestion = function() {
|
||||
// $scope.response = myPrompt.ask($scope.question);
|
||||
};
|
||||
|
||||
}]);
|
||||
|
@ -9,7 +9,8 @@
|
||||
<div ng-controller="MainCtrl">
|
||||
<label>Question</label>
|
||||
<input type="text" ng-model="question" />
|
||||
<br />
|
||||
<button ng-click="poserQuestion()">Poser la question</button>
|
||||
<br /><br />
|
||||
<b>Votre réponse:</b> <span>{{ response }}</span>
|
||||
</div>
|
||||
|
||||
|
Reference in New Issue
Block a user