From eccd0e33fcf9d1e69407de3ee61273bd0644ae1c Mon Sep 17 00:00:00 2001 From: MrLyfing Date: Tue, 29 Mar 2016 13:01:25 +0200 Subject: [PATCH] javascript last class --- src/client/exercise-01/index.js | 13 +++++++++++-- src/client/exercise-02/ng/components/fact.html | 1 + src/client/exercise-02/ng/components/fact.js | 14 ++++++++++++++ src/client/exercise-02/ng/components/layout.html | 7 ++++++- src/client/exercise-02/ng/components/layout.js | 4 ++++ 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/client/exercise-02/ng/components/fact.html create mode 100644 src/client/exercise-02/ng/components/fact.js diff --git a/src/client/exercise-01/index.js b/src/client/exercise-01/index.js index b1c8b96..087d9b6 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 () { + ['$scope', function ($scope) { this.names = []; this.addName = function () { @@ -30,7 +30,16 @@ appModule.controller('HelloController', // XXXX BAAAD NOT ANGULAR !!!! // DON'T WORK ! // FIX ME ! - setTimeout(() => this.names.shift(), 1000); + //$scope.$applyAsync(() => { + // setTimeout(() => this.names.shift(), 1000); + //}); + + setTimeout(() => { + $scope.$applyAsync(() => { + this.names.shift(); + }); + }, 1000); + //////////////////////////////////////// }; }] diff --git a/src/client/exercise-02/ng/components/fact.html b/src/client/exercise-02/ng/components/fact.html new file mode 100644 index 0000000..57c68f5 --- /dev/null +++ b/src/client/exercise-02/ng/components/fact.html @@ -0,0 +1 @@ +{{ $ctrl.fact }} \ No newline at end of file diff --git a/src/client/exercise-02/ng/components/fact.js b/src/client/exercise-02/ng/components/fact.js new file mode 100644 index 0000000..fda92d0 --- /dev/null +++ b/src/client/exercise-02/ng/components/fact.js @@ -0,0 +1,14 @@ +/** + * Created by Lyfing on 29/03/2016. + */ + +window._app.global_ng_module + .component('fact', { + templateUrl: 'client/exercise-02/ng/components/fact.html', + controller:[function () { + console.log(this.fact); + }], + bindings: { + fact: '=' + } + }); diff --git a/src/client/exercise-02/ng/components/layout.html b/src/client/exercise-02/ng/components/layout.html index 300616f..4108346 100755 --- a/src/client/exercise-02/ng/components/layout.html +++ b/src/client/exercise-02/ng/components/layout.html @@ -1,6 +1,11 @@

Exercise 2

-

Show me Chuck Norris facts :

+

Show me Chuck Norris facts : {{ facts }}

+
    +
  • + +
  • +
diff --git a/src/client/exercise-02/ng/components/layout.js b/src/client/exercise-02/ng/components/layout.js index 0eee1a4..82f45f2 100755 --- a/src/client/exercise-02/ng/components/layout.js +++ b/src/client/exercise-02/ng/components/layout.js @@ -1,11 +1,15 @@ import 'client/exercise-02/ng/services/chuck-norris'; +import 'client/exercise-02/ng/components/fact'; window._app.global_ng_module .component('layout', { templateUrl: 'client/exercise-02/ng/components/layout.html', controller: ['chuckNorris', function(chuckNorris) { + this.facts = []; + chuckNorris.fetch3Random().then((res) => { console.log(res.data.value); + this.facts = res.data.value; }) }] });