gpt4 book ai didi

javascript - Angular 组件样式指南

转载 作者:行者123 更新时间:2023-12-03 06:01:43 25 4
gpt4 key购买 nike

我正在使用angular-js-styleguide-snippets对于 Atom ,当我输入 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>'
} );
} )();

第一个片段有什么问题?

最佳答案

您必须像这样调用函数组件:

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

新的组件方法实际上采用一个对象,您可以在其中进行设置,通过调用返回该对象的函数。

查看 docs了解更多信息。

关于javascript - Angular 组件样式指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39725811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com