Import HTML template

Hey everyone!

I’d like to have in my app a specific HTML template in some pages, always the same.

I’ve read that for angular 1 we had a function called ng-include, to get HTML code from a file and inject it wherever we want.

How can we do it in Ionic2/Angular2??

This is a bad idea. Don’t do it. It breaks AOT. That said, we’ve had a couple threads on this board talking about the least bad way to do it, and the strategies are versions of: build an “alphabet” of pre-compiled components, and when you want to load your dynamic web page, download it as, e.g., a string made of that alphabet, and then build the page out of those components. But no matter how you slice it, you’re going to take a performance hit.

Ouch, that’s a bad news.

So how can I do it? Please, don’t tell me to copy/paste the code :frowning:

Why do you want to use Ionic if you already have a web page? If I were in your situation, I’d evaluate which tools I really wanted to use.

Uhm… because I’m building a mobile app?

Why can’t you just write a component that incorporates this HTML, and then include said component wherever it is needed?

It may work, but how can I do if said component needs to have an injected object?

Let’s say, I have to make a list that i populate from an array with an ngFor, I want to reuse that template in different parts of the app.

How can I pass the parameter then?

Via an input parameter. Very common Angular idiom.