Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a HTML partial without a component inside a view in Angular2

Tags:

html

angular

I have a component and its HTML file.

component:

hello-world.component.ts

import {Component} from 'angular2/core';
@Component({
  selector: 'hello-world',
  templateUrl: 'hello-world.html'
})
export class HelloWorld {
  yourName: string = '';
}

Template:

hello-world.html:

<label>Name:</label>

<h1>Hello {{yourName}}!</h1>

Now, I have other html template.html which has no component, for example it contain,

template.html

<h1>Welcome to template file</h1>
<p> This is an example file </p>

Now, I wanted to include template.html file in the hello-world.html. How can I do that.

In Angular1 I used to do,

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

How can I do it in Angular2? I am very new to Angular2.

I searched this question in many places, every one is giving an answer which has components. but didn't get my required solution.

like image 374
Sravan Avatar asked Oct 18 '22 21:10

Sravan


1 Answers

Short: isn't possible yet out of the box.

You could create a Directive like old ng-include which will do the work for you.. That Directive would load the html-file and then paste it to the DOM

like image 104
slaesh Avatar answered Oct 21 '22 04:10

slaesh