Skip to content

Instantly share code, notes, and snippets.

@bennadel
Created October 8, 2017 12:21
Show Gist options
  • Save bennadel/7bc7a94268a6e4f710abb76c8411c73b to your computer and use it in GitHub Desktop.
Save bennadel/7bc7a94268a6e4f710abb76c8411c73b to your computer and use it in GitHub Desktop.
Routable View Components Don't Need Selectors In Angular 4.4.4 - But They May Be Helpful
// Import the core angular services.
import { Component } from "@angular/core";
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
@Component({
// NOTE: Since routable views aren't embedded in template logic, we don't need to
// provide a SELECTOR - Angular will inject this component automatically as part
// of the router-outlet logic (using the "ng-component" tag).
styleUrls: [ "./a-view.component.css" ],
template:
`
<h3>
A-View Component
</h3>
<p>
This is the a-view component, noice!
</p>
`
})
export class AViewComponent {
// ...
}
// Import the core angular services.
import { Component } from "@angular/core";
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
@Component({
// For this routable component, we're going to include a SELECTOR even though it
// isn't strictly necessary (so that we can see how the view output is affected).
selector: "b-view",
styleUrls: [ "./b-view.component.css" ],
template:
`
<h3>
B-View Component
</h3>
<p>
This is the b-view component, sweet!
</p>
`
})
export class BViewComponent {
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment