首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TS文件未被调用

TS文件未被调用
EN

Stack Overflow用户
提问于 2017-06-15 09:25:47
回答 1查看 199关注 0票数 0

我正在尝试使用角2将选择器插入到我的html中。

我与appmodule.ts一起创建了html和ts文件,如下所示。

我的html页面似乎没有在加载时调用ts文件(weather.component.ts)。它没有显示在类型记录文件中定义的模板。我尝试过在html头标签中使用system.import,但是没有运气。

感谢你的投入。

代码语言:javascript
复制
<div>
    <h3>Weather for {{weather.city}}</h3>

</div>

weather.component.ts文件

代码语言:javascript
复制
import { Component } from '@angular/core';

@Component({
selector: 'weather',
template: '<h1>u are here </h1>'

})

export class WeatherComponent {
public weather: Weather;

constructor() {
this.weather = { temp: "12", summary: "Barmy", city: "London" };
}
}

interface Weather {
temp: string;
summary: string;
city: string;
}

app.module.ts

代码语言:javascript
复制
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { RouterModule } from '@angular/router';
import {ROUTER_PROVIDERS} from 'angular2/router';
import { UniversalModule } from 'angular-universal';
import { WeatherComponent } from './components/weather.component';

@NgModule({
bootstrap: [WeatherComponent],
declarations: [WeatherComponent],
imports: [UniversalModule],
})

export class AppModule {
}

platformBrowserDynamic().bootstrapModule(AppModule);
EN

回答 1

Stack Overflow用户

发布于 2017-06-15 09:31:44

因为它不是那样工作的。

当您给组件一个选择器(这里是weather)时,您应该在html中使用它作为标记。

这将为HTML提供:

代码语言:javascript
复制
<div>
    <h1>You are here</h1>
    <weather></weather>
</div>

在模板HTML中:

代码语言:javascript
复制
<h3>Weather for {{weather.city}}</h3>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44563808

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档