Тёмный
No video :(

Angular template vs templateurl 

kudvenkat
Подписаться 832 тыс.
Просмотров 245 тыс.
50% 1

Text version of the video
csharp-video-tu...
Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our RU-vid channel. Hope you can help.
/ @aarvikitchen5572
Slides
csharp-video-tu...
Angular 2 Tutorial playlist
• Angular 2 tutorial for...
Angular 2 Text articles and slides
csharp-video-tu...
All Dot Net and SQL Server Tutorials in English
www.youtube.co...
All Dot Net and SQL Server Tutorials in Arabic
/ kudvenkatarabic
In this video we will discuss template and templateurl properties of the Component decorator.
In Part 4, we have used an inline view template. Notice the code we have implemented in app.component.ts file. We have embedded the view template inline in the .ts file.
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `[h1]Hello {{name }}[/h1]`
})
export class AppComponent {
name: string = 'Angular';
}
The view template is inline in a pair of backtick characters. The first question that comes to our mind is can't we include the HTML in a pair of single or double quotes. The answer is "YES" we can as long as the HTML is in a single line. So this means the above code can be rewritten using a pair of single quotes as shown below.
template: '[h1]Hello {{name }}[/h1]'
We can also replace the pair of single quotes with a pair of double quotes as shown below, and the application still continues to work exactly the same way as before.
template: "[h1]Hello {{name }}[/h1]"
The obvious next question that comes to our mind is when should we use backticks instead of single or doublequotes
If you have the HTML in more than one line, then you have to use backticks instead of single or double quotes as shown below. If you use single or double quotes instead of backticks you will get an error.
template: `[h1]
Hello {{name }}
[/h1]`
Instead of using an inline view template, you can have it in a separate HTML file. Here are the steps to have the view template in a separate HTML file
Step 1 : Right click on the "app" folder and add a new HTML file. Name it "app.component.html".
Step 2 : Include the following HTML in "app.component.html"
[h1]
Hello {{name}}
[/h1]
Step 3 : In "app.component.ts", reference the external view template using templateUrl property as shown below. Notice instead of the "template" property we are using "templateUrl" property. Please note that templateUrl path is relative to index.html
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: 'app/app.component.html'
})
export class AppComponent {
name: string = "Angular";
}
What are the differences between template and templateUrl properties and when to use one over the other
Angular2 recommends to extract templates into a separate file, if the view template is longer than 3 lines. Let's understand why is it better to extract a view template into a seprate file, if it is longer than 3 lines.
With an inline template
1. We loose Visual Studio editor intellisense, code-completion and formatting features.
2. TypeScript code is not easier to read and understand when it is mixed with the inline template HTML.
With an external view template
1. We have Visual Studio editor intellisense, code-completion and formatting features and
2. Not only the code in "app.component.ts" is clean, it is also easier to read and understand

Опубликовано:

 

27 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 31   
@lallidilli
@lallidilli 6 лет назад
AWESOME!!! One of THE BEST Presentation ever seen. Appreciate for sharing the videos. Thanks a lot. :)
@arunbm123
@arunbm123 7 лет назад
very brilliant. You have prepared the tutorial Script very well and meticulously.
@shitalpalve1272
@shitalpalve1272 4 года назад
It is not showing error for me if I used single quote in template for more than one line. it is giving accurate output.
@dipinraman303
@dipinraman303 7 лет назад
you videos are really helping me and many to understand the concepts well.Thank you!!
@ThumbIKR
@ThumbIKR 6 лет назад
Thank you sir for this Angular 2 tutorial series. Please sir make tutorial series on Angular 4 :)
@Csharp-video-tutorialsBlogspot
As you might already know, there is a massive difference between Angular JS 1 and Angular 2. However, there is no much difference between Angular 2, Angular 4, Angular 5 and Angular 6. The way we build angular applications using Angular 2, 4 or 5 is very identical. The following video explains the difference between angular versions ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-bAx2LgQLkl8.html If you are starting to learn Angular, I suggest start with Angular 2 at the following link. ru-vid.com/group/PL6n9fhu94yhWqGD8BuKuX-VTKqlNBj-m6 And then Angular CRUD tutorial at the following link. This tutorial uses Angular 5 and covers all the concepts we were not able to cover in Angular 2 tutorial. ru-vid.com/group/PL6n9fhu94yhXwcl3a6rIfAI7QmGYIkfK5 I believe Angular CLI is a great tool to increase your productivity. So I suggest learn Angular CLI as well. ru-vid.com/group/PL6n9fhu94yhWUcq5Pc16uf8YKXoZ87Vh_ Hope you will find these resources useful to learn Angular.
@abdoessamsarhan6911
@abdoessamsarhan6911 7 лет назад
thanks sir for sharing knowledge . excellent tutorials
@npkonstan1681
@npkonstan1681 7 лет назад
Thanks a lot for teaching us!
@ihsanullah4058
@ihsanullah4058 7 лет назад
Thanks sir for sharing knowledge....
@mayank50000
@mayank50000 7 лет назад
Hi Venkat Why I am getting this error. "(systemjs) unexpected token ] syntaxerror unexpected token"
@vishnuthakur837
@vishnuthakur837 6 лет назад
But sir, If we have to use multiple html references then what should to do???
@atiqachaudhary2346
@atiqachaudhary2346 6 лет назад
can i use atom for coding instead of visual studio ?
@sanatanShishya1521
@sanatanShishya1521 6 лет назад
your videos are very nice sir, i fell your mic is somewhat more close and it's sound is too pinning my ears. plz improve it.
@atiqachaudhary2346
@atiqachaudhary2346 6 лет назад
And also ...........please explain me if i have to use multiple html references then what should to do ?
@agkumar8732
@agkumar8732 7 лет назад
Hi Venkat, Current version of angular is 4. Then what is need of learning angular 2. Like angularJs 1.x will we have to learn the complete set of new things in angular4? Please record a video to avoid this confusion.
@Brand73
@Brand73 7 лет назад
a gouri kumar yes. I have the same concern.
@npkonstan1681
@npkonstan1681 7 лет назад
Angular 1.x is the previous older version of the framework, Angular 2 is a total re-wright of the framework, same name but different. Angular 4 is the newer version of Angular 2, We have to learn Angular 4, here is the official link angular.io/
@naveenkumar-bz3rg
@naveenkumar-bz3rg 7 лет назад
Angular 4 came with minor updates from angular2, angular 2 is mandatory to learn.Happy Codding.
@DjProGamerMan
@DjProGamerMan 7 лет назад
angular 4 is simply angular 2.4 , only few changes were made !
@gmdarsh
@gmdarsh 7 лет назад
super video Thank you sir
@Yozik2
@Yozik2 7 лет назад
Is it possible refer the templateUrl property to a controller view address that renders the html via the razor engine?
@npkonstan1681
@npkonstan1681 7 лет назад
Angular's template is used to front end -the browser- Razor engine views are created to the back-end -the server- I don't think is possible to mixed them, but someone may be know better!
@pradeepyande2206
@pradeepyande2206 5 лет назад
cannot load app.component.ts. No any error. index.html not loading. only startup pg loaded.
@kalyansoma6922
@kalyansoma6922 7 лет назад
in the templateUrl instead of app if we gave ./app.component.html - there were no errors . whats the reason sir ?
@KevinPiattAdmiralP
@KevinPiattAdmiralP 6 лет назад
The dot (".") represents the parent directory of the file you are referencing. Using two dots ("..") would then represent the next directory up from the first. So in this case two dots would represent the "src" directory. So the "." and "app" are interchangeable and both will work. Perhaps one of responses here will explain it a bit better than I am: superuser.com/questions/37449/what-are-and-in-a-directory
@vikassangal2107
@vikassangal2107 5 лет назад
nice video series
@shreyas9204
@shreyas9204 6 лет назад
Hi, can someone tell me what this means? Severity Code Description Project File Line Suppression State Error Build:Class 'Subject' incorrectly extends base class 'Observable'. Angular2 D:\SoftwareLearning\OnlineLearningCodes\Angular\Angular2\Angular2 ode_modules xjs\Subject.d.ts 16 I got this error while testing the code that we saw in this video... Thanks in advance...
@RonyMattar
@RonyMattar 7 лет назад
Thanks!!
@sumersinghrana8868
@sumersinghrana8868 7 лет назад
what is system js?
@sumersinghrana8868
@sumersinghrana8868 7 лет назад
system js
@npkonstan1681
@npkonstan1681 7 лет назад
System.js is a javascript library, It is used from Angular to load modules -js files- dynamically github.com/systemjs/systemjs
Далее
Angular 2 nested components
13:00
Просмотров 293 тыс.
Angular interpolation
7:13
Просмотров 198 тыс.
Ajdarlar...😅 QVZ 2024
00:39
Просмотров 377 тыс.
Styling angular 2 components
11:18
Просмотров 197 тыс.
Data Binding - Angular (Tutorial #6)
14:49
Просмотров 51 тыс.
Liskov: The Liskov Substitution Principle
4:23
Просмотров 21 тыс.
Angular services tutorial
13:52
Просмотров 170 тыс.
Template and TemplateUrl - Angular (Tutorial #5)
4:54
Angular component output properties
16:56
Просмотров 154 тыс.