0

I have a Controller/Action which renders a View in an Angular2 template syntax; url is /angular-templates/navmenu-top. Typing this url in a browser, renders out html, so I know it works.

I would like to use that URL as a templateUrl for one of my Angular2 components:

@Component({ selector: "nav-menu-top", templateUrl: "/angular-templates/navmenu-top" })

Unfortunately, I got this error:

./ClientApp/app/components/navmenu/navmenu-top.component.ts
Module not found: Error: Can't resolve './/angulartemplates/topnav' in 'C:\Projects\...ClientApp\app\components\navmenu'
 @ ./ClientApp/app/components/navmenu/navmenu-top.component.ts 21:18-55
 @ ./ClientApp/app/app.module.ts
 @ ./ClientApp/boot-client.ts
 @ multi event-source-polyfill webpack-hot-middleware/client?path=%2F__webpack_hmr ./ClientApp/boot-client.ts

My solution is build on top of https://github.com/aspnet/JavaScriptServices. It uses webpack for bundling the resources.

Here is my webpack.config.js file: https://github.com/aspnet/JavaScriptServices/blob/dev/templates/Angular2Spa/webpack.config.js

And folder structure with a Controller code:

enter image description here

I just cant make it working. It it because of webpack config?

Thank you.

Skorunka František
  • 5,102
  • 7
  • 44
  • 69
  • Please post your directory structure btw you are doing wronh simple `/` is for root and `./` is for current and `../` is for backward – Babar Hussain Apr 03 '17 at 22:19
  • "/angular-templates/navmenu-top" is an URL which renders the HTML I think the `/` are correct = it is an absolute URL. Or what do you mean? – Skorunka František Apr 03 '17 at 22:30
  • When angular app runs out it dont points our src folder it only use assets for static paths so you should go for relative path to the template file from your component directory. And as well angular wrap up the implates code into inline template so the html files are only for development purpose always go for relative path so it can wrap before loading.. – Babar Hussain Apr 03 '17 at 22:32
  • But my template is not a static file, it is a HTML generated by MVC controller, so it should be the absolute URL to a route which actually points to an Action in a Controller. Or am I missing something here? – Skorunka František Apr 03 '17 at 22:35
  • You might want to look at [How can I use/create dynamic template to compile dynamic Component with Angular 2.0?](http://stackoverflow.com/questions/38888008/how-can-i-use-create-dynamic-template-to-compile-dynamic-component-with-angular) and [How to render asp.net mvc view into angular 2?](http://stackoverflow.com/questions/41473511/how-to-render-asp-net-mvc-view-into-angular-2). I haven't really try Angular2 yet; I only have [Angular1](https://github.com/WinLwinOoNet/AngularAspNet). If you figure out, please share your solution too. – Win Apr 03 '17 at 23:15
  • Found the answer here: http://stackoverflow.com/questions/41473511/how-to-render-asp-net-mvc-view-into-angular-2 – Skorunka František Apr 04 '17 at 10:32

0 Answers0