gpt4 book ai didi

angularjs - 将数据从父级传递到子级 angular.js 组件

转载 作者:行者123 更新时间:2023-12-04 01:53:20 24 4
gpt4 key购买 nike

<分区>

我有父组件:

(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 = () => {
}
}
})
})()

parent.html

<child-component></child-component>

child.html

<p>{{parentData}}</p>

所以我想访问我的子组件中的 parentData 以在我的子组件中显示字符串“test”。我该怎么做?我阅读了一些有关绑定(bind)的内容,但我不知道如何在此示例中使用它。

感谢您的任何建议。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com