2016-09-27 42 views
0

我使用angular-js-styleguide-snippetsAtom,其中,当我在我的编辑输入ngcomponent,扩展到以下结构:角度分量风格指南

(function() { 
    'use strict'; 

    angular 
     .module('arroyo') 
     .component('intro', component); 

    /* @ngInject */ 
    function component() { 
     var settings = { 
      template: '<h1>test</h1>', 
      controller: Controller, 
     }; 

     return settings; 
    } 

    Controller.$inject = []; 

    /* @ngInject */ 
    function Controller() { 

    } 
})(); 

但是,使用上面的代码似乎并不奏效。虽然没有控制台错误,但组件本身(<intro></intro>)不显示任何内容。经过一番摆弄周围,我发现,使用下面的作品的代码如预期:

(function() { 
    'use strict'; 

    angular 
     .module('arroyo') 
     .component('intro', { 
      template: '<h1>test</h1>' 
     }); 
})(); 

有什么不对的第一个片段?

回答

1

必须调用该功能模块,像这样:

angular 
    .module('arroyo') 
    .component('intro', component()); 

新的组件方法实际上发生在你给的设置对象,通过调用返回该对象的功能。

查看docs了解更多信息。