0

I'm trying to create a component directive using AngularJS 1.5. I'm passing the $scope variable defined in the controller to the component directive. But it's not rendering.

Here is the component directive:

.component('myComp', {
   scope: {},
   bindToController: {
       info: '=info'
   },

   template: [

       '<table<tr>',
       '<td>{{ $ctrl.info }}</td>',
       '</tr>',
       '</tbody>',
       '</table>'
   ].join('')

});

Here is the view

<my-comp info="employee"></my-comp>

But nothing is displayed and no error in browser console.

iJade
  • 23,144
  • 56
  • 154
  • 243

2 Answers2

0

Things Have Changed -- Again

Components now ignore the bindToController property. Instead use bindings.

.component('myComp', {
   //scope: {},

   //obsolete
   //bindToController: {

   //Use instead
   bindings: {       
       info: '=info'
   },

   template: [

       '<table<tr>',
       '<td>{{ $ctrl.info }}</td>',
       '</tr>',
       '</tbody>',
       '</table>'
   ].join('')

});

The DEMO on JSFiddle

For more information, see AngularJS Developer Guide - Understanding Components.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
-1

Try this one

.component('myComp', {
 restrict: 'AE',
 scope: {info: '='},
 template: [

   '<table<tr>',
   '<td>{{ info }}</td>',
   '</tr>',
   '</tbody>',
   '</table>'
 ].join('')
});
Sanjay Sahani
  • 565
  • 4
  • 14