V
V
Valeriy Donika2016-12-13 23:06:02
Angular
Valeriy Donika, 2016-12-13 23:06:02

Angular 1.6.0 onInit how does it work?

Even I can’t redeem if info is transmitted from one component,

bindings: {
            item: '=',
        },

writing
const ctrl = this;

                this.$onInit = function() {
                    ctrl.item = this.item;
                };

writes that undefined ....
So how does it work now? :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nicholas, 2016-12-13
@healqq

What has changed is that you cannot use bindings in the body of the controller itself.
They will only appear when $onInit is called.
Those. if you need to calculate some value from the binding, you can't do it like this:

bindings : {
   item: '<'
}
function ctrl() {
    const vm = this;
    vm.coolVal = this.item * 2;
}

Because bindings will not be initialized yet. You need to do it in $onInit.

S
Stepanya, 2016-12-14
@Stepanya

bindings: {
            item: '<'
        },

const ctrl = this;

                this.$onInit = function() {
                    console.log(ctrl.item);
                };

https://jsfiddle.net/jxcj2w79/2/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question