Angular2 Tricks

Hi Friends welcome, in this section, I will introduce you with some of the tips and tricks of Angular2. That I came across while doing my handsfree with AngularJS2. I hope these information's will help you.

💭What if I will use both template and templateUrl field in my Component? Is it going to through me Error, if not then which field will get considered?
      Ex :
@Component({
  selector: 'banchha',
  template:` <h1>Testing template attribute</h1>  `,
  templateUrl: './app.component.html'
})
💨 The answer is that you can use both of them in the Component, it might be logically not correct but syntactically Angular2 allows it(as on 1st May 2017), so no error will be thrown by the transpiler.

Answering next which field will be considered, the answer is that the field(between template and templateUrl) that occurs last in the Component,  will get considered, i:e in above example the templateUrl comes later so it will be considered.

Comments

Popular posts from this blog

Tutorial-6 Pipes

Tutorial-4 Data Bindings in Angular