I'm new to .component() in Angular 1.5+ and I'm trying to create data in the top level app controller, and pass it to a child component. However, printing to the console gives me undefined in the following example and I'm not sure why.
index.html
<!DOCTYPE html>
<html>
<head>
<script src="Scripts/angular.js"></script>
<script src="app.js"></script>
<title></title>
<meta charset="utf-8" />
</head>
<body ng-app="myApp" ng-controller="myController as vm">
<app name="vm.myName"></app>
</body>
</html>
app.js
var app = angular.module("myApp", []);
app.controller("myController", ['$scope', function ($scope) {
console.log("myController!");
$scope.myName = "Rick";
}]);
app.component("app", {
template: '<h1>Hello World</h1>',
bindings: {
name: '='
},
controller: function () {
console.log(this.name); <-- prints undefined
}
});