Angular 1 - Using the bindings in the controller - Component

1

I'm using AngularJs, in creating a component I need to access the bindings in the controller of my component.

In html I'm calling the component like this:

<component type='tipo' urlid='meuid'></component>

I'm using the second syntax for bindigs:

bindings: {
    type: '@',
    urlid: '@'
}

And in the controller I'm using:

function meuController() {
    var vm = this;
    console.log(vm);
    console.log(vm.type);
    console.log(vm.urlid);
}

I'm having this comeback:

As you can see in the image the attributes then in the controller (vm) but when I access them I get the undefined return.

How do I access these attributes?

    
asked by anonymous 16.01.2017 / 12:25

2 answers

2

Follow the code below:

vm.$onInit = function () {
    console.log(vm.type);
    console.log(vm.urlId);
}

So it will only access bind when the controller is started.

    
16.01.2017 / 19:54
1

I was able to access the data using $timeOut , like this:

$timeout(function () {
    console.log(vm.type);
    console.log(vm.urlId);
})

Possibly there is some delay for Angular to recognize the parameters. This way I'm having a go.

    
16.01.2017 / 13:24