Angular @Component 在单独的导出文件中 class
Angular @Component in separate file of export class
通过 angularjs
,我们学会了像这样构造我们的代码。
item.module.js:
angular.module('name', [ deps ] )
item.component.js
angular.module('name')
.component({ declaration, controller: 'controller', template: template})
item.controller.js
angular.module('name')
.controller('controller', code..);
item.html
<html>
然而 angular
组件与其控制器一起在单个文件中声明
@Component({ templateUrl: template })
export class BlaComponent {}
有没有办法把这两个声明放在单独的文件中?
这是想要的吗(赞成/反对)
奖金问题(我还在谷歌搜索这个问题):是否有任何适用于大型项目和文件结构的指南?
@Component 只是一个包含 class 元数据的装饰器。换句话说,它只是以更优雅的方式为您的 class 定义内容。
The @Component function takes the configuration object and turns it into metadata that it attaches to the component class definition. Angular discovers this metadata at runtime and thus knows how to do "the right thing".
Angular2+没有控制器,但是class。换句话说,您不会将装饰器与 class.
分开
检查 Official Angular 2 Styleguide Application Structure to get some idea how to structure your code. Also check the Angular CLI 项目以促进您的应用程序开发。请注意,Angular CLI 使用官方 Angular 2 样式指南和约定,非常方便,而且它为您提供了基本结构,您可以从中轻松地继续扩展您的项目。
我们的团队正在使用 official style guide,我们发现它非常适合我们的需求。
回答你的问题,你不能将 @Component
装饰器从它的 class 中分离出来,你也不必这样做。您可能仍然将模板和样式放在单独的文件中,实际上是 officially recommended in this section.
通过 angularjs
,我们学会了像这样构造我们的代码。
item.module.js:
angular.module('name', [ deps ] )
item.component.js
angular.module('name')
.component({ declaration, controller: 'controller', template: template})
item.controller.js
angular.module('name')
.controller('controller', code..);
item.html
<html>
然而 angular
组件与其控制器一起在单个文件中声明
@Component({ templateUrl: template })
export class BlaComponent {}
有没有办法把这两个声明放在单独的文件中? 这是想要的吗(赞成/反对)
奖金问题(我还在谷歌搜索这个问题):是否有任何适用于大型项目和文件结构的指南?
@Component 只是一个包含 class 元数据的装饰器。换句话说,它只是以更优雅的方式为您的 class 定义内容。
The @Component function takes the configuration object and turns it into metadata that it attaches to the component class definition. Angular discovers this metadata at runtime and thus knows how to do "the right thing".
Angular2+没有控制器,但是class。换句话说,您不会将装饰器与 class.
分开检查 Official Angular 2 Styleguide Application Structure to get some idea how to structure your code. Also check the Angular CLI 项目以促进您的应用程序开发。请注意,Angular CLI 使用官方 Angular 2 样式指南和约定,非常方便,而且它为您提供了基本结构,您可以从中轻松地继续扩展您的项目。
我们的团队正在使用 official style guide,我们发现它非常适合我们的需求。
回答你的问题,你不能将 @Component
装饰器从它的 class 中分离出来,你也不必这样做。您可能仍然将模板和样式放在单独的文件中,实际上是 officially recommended in this section.