我是新來的.component()在Angular 1.5+和我試圖在頂級應用程序控制器中創建數據,並將其傳遞給子組件。但是,打印到控制檯使我在下面的示例中未定義,我不知道爲什麼。角度1.5組件沒有變量傳遞給組件
的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
}
});
啊,我在混合2種模式。非常感謝! – user441521
@ user441521不客氣:) –