Plunker中的Angular 4.1.0:添加组件会返回404 XHR错误 [英] Angular 4.1.0 in Plunker: adding component returns 404 XHR Error
问题描述
我正在尝试将Angular 4与Plunker一起使用,但无法添加新组件.网址是: https://plnkr.co/edit/1umcXTeug2o6eiZ89rLl?p=preview
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
我刚刚用最少的声明创建了一个新组件-mycomponent.ts
.
然后,在app.ts
中,添加导入声明:
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";
并在@NgModule装饰器内的声明数组中添加组件:
and add the component in the declarations array within the @NgModule decorator:
declarations: [ App, MyComponent ],
最后一位将其破坏并返回404 XHR错误.到目前为止,我只是在更改导入声明(是否为"./"),组件模板的内联/URL模板,chrome/firefox浏览器,但到目前为止没有任何效果.我倾向于认为这是Plunker的错:S
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
推荐答案
将mycomponent.ts
的名称更改为src/mycomponent.ts
,它将起作用.
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).
不要忘记将<combo-compo></combo-compo>
添加到您的app.ts
模板中.
Don't forget to add <combo-compo></combo-compo>
to your app.ts
template.
签出:
这篇关于Plunker中的Angular 4.1.0:添加组件会返回404 XHR错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!