- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
随着 AngularJS V1.7 的发布,预先分配绑定(bind)到的选项已被弃用和删除:
Due to 38f8c9, directive bindings are no longer available in the constructor.
To migrate your code:
- If you specified
$compileProvider.preAssignBindingsEnabled(true)
you need to first migrate your code so that the flag can be flipped tofalse
. The instructions on how to do that are available in the "Migrating from 1.5 to 1.6" guide. Afterwards, remove the$compileProvider.preAssignBindingsEnabled(true)
statement.
Due to bcd0d4, pre-assigning bindings on controller instances is disabled by default. We strongly recommend migrating your applications to not rely on it as soon as possible.
Initialization logic that relies on bindings being present should be put in the controller's
$onInit()
method, which is guaranteed to always be called after the bindings have been assigned.— AngularJS Developer Guide - Migrating from v1.5 to v1.6 - $compile
$onInit
Life-Cycle Hook 时的用例是什么? ?我们什么时候可以将代码留在 Controller 构造函数中?
最佳答案
代码必须移入 $onInit
函数,当它依赖于绑定(bind)时,因为这些绑定(bind)在 this
中不可用在构造函数中。它们在组件类的实例化之后被分配。
例子:
你有一个这样的状态定义:
$stateProvider.state("app", {
url: "/",
views: {
"indexView": {
component: "category"
}
},
resolve: {
myResolve: (someService) => {
return someService.getData();
}
}
});
myResolve
的结果像这样到您的组件:
export const CategoryComponent = {
bindings: {
myResolve: "<"
},
controller: Category
};
this.myResolve
在
constructor
在
$onInit
你会看到这样的东西:
constructor() {
console.log(this.myResolve); // <-- undefined
}
$onInit() {
console.log(this.myResolve); // <-- result of your resolve
}
constructor() {
this.myArray = [];
this.myString = "";
}
$onInit
中。
关于angularjs - 何时使用 AngularJS `$onInit` 生命周期 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51273521/
我正在开发一个使用多个 turtle 的滚动游戏。玩家 turtle 根据按键命令在 Y 轴上移动。当危害和好处在 X 轴上移动时,然后循环并改变 Y 轴位置。我尝试定义一个名为 colliding(
我不明白为什么他们不接受这个作为解决方案,他们说这是一个错误的答案:- #include int main(void) { int val=0; printf("Input:- \n
我正在使用基于表单的身份验证。 我有一个注销链接,如下所示: 以及对应的注销方法: public String logout() { FacesContext.getCurren
在 IIS7 应用程序池中有一个设置 Idle-time out 默认是 20 分钟,其中说: Amount of time(in minutes) a worker process will rem
我是一名优秀的程序员,十分优秀!