0

I'm evaluating the lastest bits of Angular (7+) and CLI. I've done parts of the 'Tour of Heroes' tutorial. I can run 'ng build' to get the production bits.

However, an important requisite is the use of MVC views for component templates.

So instead of

templateUrl: './app.component.html'

I want to use

templateUrl: '/Template/Index'

for various reasons (translated templates being one). I do understand this is not the 'pure' Angular way of doing thing.

With this code in place, 'ng build' no longer works:

ERROR in ./src/app/app.component.ts

Module not found : error : Can't resolve './/Template/Index' in 'D:\Angular\TourOfHeroes\TourOfHeroes\src\app'

I've searched for hours how to omit building the templates, but I can't find an answer. ng eject is depricated. It guides me to ngx-build-plus, but I don't see how this can help me.

What steps should I take to get this working?

EDIT:

Question How to using MVC views (*.cshtml) as templates in Angular 2? is not related. I know how to use MVC views in Angular. What I don't know is how to tell 'ng build' to omit these templates (as they are not static at all).

Community
  • 1
  • 1
NetWave
  • 379
  • 3
  • 12
  • Why do you want to use angular if you're already using .net views? – Friso Mar 19 '19 at 08:28
  • Can you elaborate more on what you are trying to do and why? – Friso Mar 19 '19 at 09:10
  • Possible duplicate of [How to using MVC views (\*.cshtml) as templates in Angular 2?](https://stackoverflow.com/questions/33634916/how-to-using-mvc-views-cshtml-as-templates-in-angular-2) – Friso Mar 19 '19 at 09:23
  • @Friso: No, not a duplicate. I know how to use MVC views with Angular, but I can't get it to work with 'ng build' to build production bits. – NetWave Mar 19 '19 at 09:27
  • under MVC views you mean .cshtml files, with razor syntax? – robert Mar 19 '19 at 20:51
  • @robert: Yes. They are processed on the server, delivering Angular templates (as in 'Hi {{firstName}}') to the client. – NetWave Mar 20 '19 at 12:59

1 Answers1

1

You might have to switch to webpack/rollup/systemjs-builder in order to create builds omitting baking in templates. Angular CLI doesn't support such scenario.

One caveat - you will be building in development mode, aot doesn't support dynamic templates (not in straightforward way)

kuekue
  • 11
  • 1
  • Hi Keukue, thanks for taking the time to answer this (relatively) old question! I will look into this. Do you have any experience replacing Angular CLI yourself? Do you happen to know a good tutorial that should get me started? – NetWave Sep 02 '19 at 07:58
  • I tried all the mentioned tools. The best option would be wepback. There's bunch of tutorials online. I followed few of them, as each pertains to different versions of angular, typescript and other libraries you use. The most promising one I'd recommend is https://www.freecodecamp.org/news/how-to-configure-webpack-4-with-angular-7-a-complete-guide-9a23c879f471/ – kuekue Sep 10 '19 at 20:32