gpt4 book ai didi

javascript - Controller 内部的 Angular 1.6 绑定(bind)

转载 作者:数据小太阳 更新时间:2023-10-29 06:00:22 25 4
gpt4 key购买 nike

我试图通过绑定(bind)将一些参数传递给我的组件,但不幸的是我没有在我的 Controller 中使用这些参数,这是我的代码:

angular.module('project1').component('menu', {
templateUrl: '/static/js/templates/menu.template.html',
bindings: {
rid: '@'
},
controller: ['Restaurant', function RestaurantListController(Restaurant) {
console.log(this.rid);
console.log(this);
this.restaurant = Restaurant.get({restaurantId: this.rid});
}]
});

HTML 组件:

<menu rid="1"></menu>

有趣的是,我可以访问模板中的参数,当我执行 2 个控制台日志时,第一个是未定义的,但在第二个中我可以看到 rid 变量...所以,我真的不知道不明白我错过了什么。

最佳答案

在 Angular 1.6 中,您的绑定(bind)将在 $onInit 方法上准备就绪,而不是之前。

如果您需要重新启用自动绑定(bind) https://toddmotto.com/angular-1-6-is-here#re-enabling-auto-bindings

关于javascript - Controller 内部的 Angular 1.6 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41323029/

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