question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support overriding selectors of directives on import.

See original GitHub issue

It should be possible to override the selector of a component on import.

@Decorator({
  selector: 'some-selector'
})
class Directive {}

@Component(...)
@Template({
  directives: [
    new DirectiveBinding({key: Directive, selector: 'other-selector')
  ]
})

PROBLEMS

  • this would make it hard to know all selectors statically, as it requires execution of code to know what the selector is.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
mheverycommented, Jul 1, 2016

Will not implement.

2reactions
PatrickJScommented, Mar 11, 2015

why not something more declarative Directive.selectorAs('other-selector') or something like

@Component(...)
@Template({
  directives: [
    Directive.selectorAs('other-selector').templateUrlAs('other.html')
  ]
})
export class Cmp {
}

define overwrites in the prototype or

@Component(...)
@Template({
  directives: [
    Overwrite(Directive)
      .component({ selector: 'other-selector' })
      .template({ url: 'other.html' })
  ]
})
export class Cmp {
}

create a container but then the container needs to know the types of annotations so what if you can just annotate the container which will overwrite the Directive

@Component(...)
@Template({
  directives: [
    @Component({ selector: 'other-selector' })
    @Template({ url: 'other.html' })
    Overwrite(Directive)
  ]
})
export class Cmp {
}

I’m not even sure if that’s possible or even if that is something people want since it’s even more code but its pretty simple to reason about why that works perhaps.

Should there be a way to define a suite of directives? or at least best practice

import {Component, Template, directivePrefixer} from 'angular2/angular2';
import {button} from 'material-directives/suite';
// prefix helper in suite or angular itself
import * as ngMaterial, {prefix} from 'material-directives/suite';

@Component(...)
@Template({
  directives: [
    prefix('ng', ngMaterial) // or built in helper from ng2 as directivePrefixer
  ]
})
export class Cmp {
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there an easy way to overwrite base directive?
Reimplement/extend the directive by yourself and import it in a module instead of the original one · Use the "adjusted" fork of angular...
Read more >
Overriding dependencies in the Angular injector hierarchy
Overriding dependencies in Angular. Overriding dependencies in Angular requires two key properties: provide — this points to the dependency ...
Read more >
Use Angular directives to extend components that you don't own
Angular directives allow us to extend components without changing their internal code. This is useful to bring a consistent UX to 3rd party ......
Read more >
Overriding CSS properties of third-party components in Angular
You can override a third-party component's CSS properties either at an enclosing component or global level. Unless you want to affect all the ......
Read more >
Directive - Angular
selector1, selector2 : Select if either selector1 or selector2 matches. Angular only allows directives to apply on CSS selectors that do not cross...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found