0

Greetings to the community

Normally in Angular 5, I have the following format from @Component when I use an external template, it works ok

@Component({
selector: 'app-home',
templateUrl: '../tpl/default/home.html',
styleUrls: ['./home.component.css']
})

I am needing that, according to data obtained from an api, the name of the folders where I look for the html, are dynamic

I have tried several ways to pass the route dynamically, but it always returns the following error:

Failed to compile. ./src/app/home/home.component.ts Module not found: Error: Can't resolve './{{template}}' in 'C:\angular\src\app\home'

Is there any way to solve this?

Thanks for the help

4
  • What is different in between all the html? Commented Apr 26, 2018 at 1:56
  • All the html for the home are totally different, belong one for each sector of the company Commented Apr 26, 2018 at 1:59
  • So they need to do different functions too? Commented Apr 26, 2018 at 2:00
  • the logic is similar in most cases, but the view must change according to the sector Commented Apr 26, 2018 at 2:02

1 Answer 1

2

You can't update code dynamically to load new template in angular, because of angular AOT compilation.

Resolving your issue: You can create dynamic components for each view and an base controller which contains logic for each view. Your base controller can be extended by each components controller individually. So now your components can have their logic as well as base controller logic. Use angular routing to change the view dynamically at run time.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.