Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javascript last class #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/client/exercise-01/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ appModule.component('layout', {
});

appModule.controller('HelloController',
[function () {
['$scope', function ($scope) {
this.names = [];

this.addName = function () {
Expand All @@ -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);

////////////////////////////////////////
};
}]
Expand Down
1 change: 1 addition & 0 deletions src/client/exercise-02/ng/components/fact.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span>{{ $ctrl.fact }}</span>
14 changes: 14 additions & 0 deletions src/client/exercise-02/ng/components/fact.js
Original file line number Diff line number Diff line change
@@ -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: '='
}
});
7 changes: 6 additions & 1 deletion src/client/exercise-02/ng/components/layout.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<div id="content">
<div class="container">
<h1 id="header">Exercise 2</h1>
<p>Show me Chuck Norris facts :</p>
<p>Show me Chuck Norris facts : {{ facts }}</p>
<ul>
<li ng-repeat="fact in $ctrl.facts">
<fact fact="fact.joke"></fact>
</li>
</ul>
</div>
</div>
4 changes: 4 additions & 0 deletions src/client/exercise-02/ng/components/layout.js
Original file line number Diff line number Diff line change
@@ -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;
})
}]
});