0
我想將選擇器插入到我的HTML使用角度2.TS文件沒有被調用
我已經創建了html和ts文件以及appmodule.ts。
我的html頁面似乎沒有調用它的負載上的ts文件(weather.component.ts)。它不顯示在typescript文件中定義的模板。我曾嘗試在html頭標中使用system.import,但沒有運氣。
欣賞您的輸入。
HTML
<div>
<h3>Weather for {{weather.city}}</h3>
</div>
weather.component.ts文件
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
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);
感謝。我現在已經更新了html和ts文件(上面沒有提供模板html)。仍然沒有運氣,請讓我知道。
You are here
從您的文章,你有兩個一個HTML文件和組件中的模板。但無論如何,它是否適合你? – trichetriche
是的,我有一個HTML文件ts文件分別。 ts文件有一個模板。 天氣是ts文件中定義的選擇器,我需要在html文件中顯示weather.city的值。 – chint