简体   繁体   中英

what type of prefix selector rules do you use for angular components?

I ran tslint against my ng2 app using the default tslint.json configuration. tslint returned the following error:

The selector of the component "MyComponent" should have prefix "app" ( https://angular.io/styleguide#style-02-07 )

As a general strategy, if you had an ng2 app named MyApp, would you prefix all selectors like this?:

  • my-app-users
  • my-app-accounts

Or would you not be this specific with the selector and just use a generic "app" prefix to indicate that the selectors belong to the primary app? For example:

  • app-users
  • app-accounts

Technically, no 3rd party component would have a prefix of "app-" b/c this would clearly risk conflict with ng components in the consuming app and also would not clearly describe the purpose/role of the third party component.

I would say to use your project specific prefix and configure that in your tslint configuration.

for my project I am using cfs and its short form of the project name and other team know this by name. Its really person that what name you will choose for all your components.

And for make sure to not use ng as its being used by angular team and others will really confused to see if its your component or angular core component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM