aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-02-03 21:42:19 +0100
committerTeddy Wing2017-02-03 21:42:19 +0100
commitce84731d02d0986a1172e80e690b6601f8c00e32 (patch)
treee680dc3301acf8f2d8420563cf108222cd2aab27
parentd60b1eb67c2c4878955458f5378911d5d54b6a95 (diff)
downloadAngular-tutorial-ce84731d02d0986a1172e80e690b6601f8c00e32.tar.bz2
hello.component.js: Add a button that prints the name to the console
Clicking on the button prints the current name to the console. Normally you wouldn't include the debug console in the controller scope, but this is here as an example to illustrate the action. The window isn't available to the controller's scope, it only includes what it defines on its scope.
-rw-r--r--app/assets/javascripts/hello/hello.component.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/app/assets/javascripts/hello/hello.component.js b/app/assets/javascripts/hello/hello.component.js
index 056cd39..366e5d5 100644
--- a/app/assets/javascripts/hello/hello.component.js
+++ b/app/assets/javascripts/hello/hello.component.js
@@ -5,9 +5,15 @@
.component('hello', {
template:
'<h2>Hello {{ $ctrl.name }}</h2>' +
- '<input type="text" ng-model="$ctrl.name" />',
+ '<div>' +
+ '<input type="text" ng-model="$ctrl.name" />' +
+ '</div>' +
+ '<div>' +
+ '<button ng-click="$ctrl.console.log($ctrl.name)">Print to console</button>' +
+ '</div>',
controller: function() {
this.name = '';
+ this.console = window.console;
}
});