Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Pretty new to Angular and doing a small pilot project using Angular 5 and Visual Code. I am trying to use ng-include and the template doesn't get displayed.

  src
     add-device
        add-device.component.html
        add-device.component.scss
        add-device.component.spec.ts
        add-device.component.ts
     edit-device
        edit-device.component.html
        edit-device.component.scss
        edit-device.component.spec.ts
        edit-device.component.ts
     templates
        device.html
     app.module.ts
     app.coponent.ts
     app.component.html
     ....

simple device.html code

<div>Include is working!</div>

add-device.component.html

<div ng-include="" src="'templates/device.html'">
    <div>More unique elements here!</div>
</div>

I also tried following

<div ng-include="" src="'templates/device.html'"></div>

<div ng-include="'templates/device.html'"></div>

Following gives error, ng-include is not recognized.

<ng-include src="'templates/device.html'"></ng-include>

Objective is to use device.html template code from both add and edit device components. I am using typescript to manage the project. When i look at the Sources in debugger, i do not even see device.html file in source list.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Angular doesn't have a ng-include as AngularJS used to have.

In Angular, you can create a component like this:

@Component({
    selector: 'app-device',
    templateUrl: './device.html'
})
class DeviceComponent {}

And then, instead of:

<div ng-include="'templates/device.html'">

you do:

<app-device></app-device>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...