Angular 1.6 bindings inside the controller

I am trying to pass some parameters to my component via bindings, but unfortunately I was not lucky to use these parameters in my controller, this is my code:

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 component:

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

It is interesting that I can access the parameters in the template, and when I make a 2-console log, the first one is undefined, and in the second I see the rid variable ... therefore, I really do not understand what I am missing.

+5
source share
1 answer

With angular 1.6, your bindings will be ready for the $ onInit method, not before.

If you need to enable automatic bindings again https://toddmotto.com/angular-1-6-is-here#re-enabling-auto-bindings

+8
source

Source: https://habr.com/ru/post/1261878/


All Articles