Angular 4.1.0 in Plunker: adding component returns 404 XHR Error

扶醉桌前 提交于 2019-12-11 06:13:58

问题


I'm trying to use Angular 4 with Plunker and I can't manage to add a new component. The URL is: https://plnkr.co/edit/1umcXTeug2o6eiZ89rLl?p=preview

I've just created a new component - mycomponent.ts - with the minimum of declarations. Then, in app.ts, I'm adding the importing declaration:

import {MyComponent} from "./mycomponent";

and add the component in the declarations array within the @NgModule decorator:

 declarations: [ App, MyComponent ],

This last bit breaks it and returns a 404 XHR error. So far I just played with changing the import declaration ("./" or not), inline/URL template for the component template, chrome/firefox browsers but nothing works so far. I'm inclined to think it's Plunker's fault :S


回答1:


Change the name of mycomponent.ts to src/mycomponent.ts and it will work.

The error is because it can't include the component (bad pathing).

Don't forget to add <combo-compo></combo-compo> to your app.ts template.

Check it out:



来源:https://stackoverflow.com/questions/43678614/angular-4-1-0-in-plunker-adding-component-returns-404-xhr-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!