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.

6
  • Please post your directory structure btw you are doing wronh simple / is for root and ./ is for current and ../ is for backward Commented Apr 3, 2017 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? Commented Apr 3, 2017 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.. Commented Apr 3, 2017 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? Commented Apr 3, 2017 at 22:35
  • You might want to look at How can I use/create dynamic template to compile dynamic Component with Angular 2.0? and How to render asp.net mvc view into angular 2?. I haven't really try Angular2 yet; I only have Angular1. If you figure out, please share your solution too. Commented Apr 3, 2017 at 23:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.