templateUrl对我不起作用 [英] templateUrl does not work for me

查看:65
本文介绍了templateUrl对我不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照angular.io入门项目使用种子结构.到目前为止一切正常.

I use the seed structure as per angular.io get started project. Everything OK so far.

现在,我想更改顶部组件以使用单独文件中的视图,但遇到麻烦了.工作代码为:

Now I wanted to change the top component to have a view from a separated file and I get into troubles. The working code is:

import {Component, View} from 'angular2/core';
@Component({
       selector: 'my-app',
       template: '<h1>Angular2</h1>',
       directives: []
})
export class AppComponent {
       constructor() {  
       }
}

然后我将模板更改为templateUrl,如下所示:

Then I change the template to templateUrl like so:

templateUrl: 'app.component.html',

我在此文件中拥有与以前完全相同的代码

where I have in this file the exact same code as before

<h1>Angular2</h1>

工作似乎很明显,但事实并非如此.它不会吐出错误,但除了入门演示中的正在加载...."消息外,不会显示任何内容

Seems to be obvious to work but it does not. It does not spit errors but it does not display anything except the 'loading....' message as in the get started demo

感谢您的帮助

彼得

推荐答案

在@Component装饰器中添加moduleId:module.id.如果您没有该文件,那么Angular 2将在根目录下查找文件.

Add moduleId: module.id in the @Component decorator. If you don't have that then Angular 2 will be looking for your files at the root level.

import {Component} from 'angular2/core';

@Component({
  selector: 'my-app',
  moduleId: module.id,
  templateUrl: 'app.component.html'
})

export class AppComponent { }  

检查此文章

这篇关于templateUrl对我不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆