【发布时间】:2019-01-29 03:36:00
【问题描述】:
我有父组件:
(function () {
angular.module('app.module')
.component('parentComponent', {
templateUrl: 'parent.html',
controllerAs: 'vm',
controller: function ($scope) {
this.$onInit = () => {
$scope.parentData = 'test'
}
})
})()
子组件
(function () {
angular.module('app.module').component('childComponent', {
templateUrl: 'child.html',
controllerAs: 'vm',
controller: function () {
this.$onInit = () => {
}
}
})
})()
父.html
<child-component></child-component>
child.html
<p>{{parentData}}</p>
所以我想在我的子组件中访问 parentData 以在我的子组件中显示字符串“test”。我该怎么做?我读了一些关于绑定的东西,但我不知道如何在这个例子中使用它。
感谢您的任何建议。
【问题讨论】: