From 85c36dee1f98336e2ce0ca2e2d5b2c3dd41d4857 Mon Sep 17 00:00:00 2001 From: Robin THONI Date: Thu, 31 Mar 2016 21:44:32 +0200 Subject: [PATCH] exo 1-2 --- src/client/exercise-01/index.js | 4 ++-- src/client/exercise-02/ng/components/layout.html | 1 + src/client/exercise-02/ng/components/layout.js | 14 ++++++++++++-- src/client/exercise-02/ng/services/chuck-norris.js | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/client/exercise-01/index.js b/src/client/exercise-01/index.js index b1c8b96..92ca223 100755 --- a/src/client/exercise-01/index.js +++ b/src/client/exercise-01/index.js @@ -17,7 +17,7 @@ appModule.component('layout', { }); appModule.controller('HelloController', - [function () { + ['$timeout', function ($timeout) { this.names = []; this.addName = function () { @@ -30,7 +30,7 @@ appModule.controller('HelloController', // XXXX BAAAD NOT ANGULAR !!!! // DON'T WORK ! // FIX ME ! - setTimeout(() => this.names.shift(), 1000); + $timeout(() => this.names.shift(), 1000); //////////////////////////////////////// }; }] diff --git a/src/client/exercise-02/ng/components/layout.html b/src/client/exercise-02/ng/components/layout.html index 300616f..c415e6f 100755 --- a/src/client/exercise-02/ng/components/layout.html +++ b/src/client/exercise-02/ng/components/layout.html @@ -2,5 +2,6 @@

Exercise 2

Show me Chuck Norris facts :

+
diff --git a/src/client/exercise-02/ng/components/layout.js b/src/client/exercise-02/ng/components/layout.js index 0eee1a4..c347a50 100755 --- a/src/client/exercise-02/ng/components/layout.js +++ b/src/client/exercise-02/ng/components/layout.js @@ -3,9 +3,19 @@ import 'client/exercise-02/ng/services/chuck-norris'; window._app.global_ng_module .component('layout', { templateUrl: 'client/exercise-02/ng/components/layout.html', - controller: ['chuckNorris', function(chuckNorris) { + controller: ['chuckNorris', '$scope', function(chuckNorris, $scope) { + $scope.jokes = []; chuckNorris.fetch3Random().then((res) => { - console.log(res.data.value); + $scope.jokes = res.data.value; }) }] }); + + +window._app.global_ng_module + .component('joke', { + template: '

{{$ctrl.joke.joke}}

', + bindings: { + joke: '=' + } + }); \ No newline at end of file diff --git a/src/client/exercise-02/ng/services/chuck-norris.js b/src/client/exercise-02/ng/services/chuck-norris.js index aa503a9..46d4aa8 100755 --- a/src/client/exercise-02/ng/services/chuck-norris.js +++ b/src/client/exercise-02/ng/services/chuck-norris.js @@ -1,11 +1,11 @@ -const URL = 'http://api.icndb.com/jokes/random/3?exclude=[nerdy,explicit]'; +//const URL = 'http://api.icndb.com/jokes/random/3?exclude=[nerdy,explicit]'; window._app.global_ng_module .service('chuckNorris', ['$http', function($http) { this.fetch3Random = function() { - return $http.get(URL); + return $http.get('http://api.icndb.com/jokes/random/3?exclude=[nerdy,explicit]'); }; }]);