【发布时间】:2020-05-24 18:17:53
【问题描述】:
我的疑问是以下一个我有两个组件,一个是演示文稿,另一个是角度 9 的容器,当我尝试在组件容器中导入演示文稿的组件时给我一个语法错误我希望你能帮助解决这个问题.谢谢
当前天气.component.ts
import { Component, OnInit } from '@angular/core';
import { CurrentWeatherService } from '../services/current-weather.service';
@Component({
selector: 'app-current-weather',
templateUrl: './current-weather.component.html',
styleUrls: ['./current-weather.component.scss'],
})
export class CurrentWeatherComponent implements OnInit {
constructor(public weatherService: CurrentWeatherService) {}
ngOnInit() {
}
}
天气卡.component.ts
import { Component, OnInit, Input } from '@angular/core';
import { Weather } from 'src/structures/weather.structure';
@Component({
selector: 'app-weather-card',
templateUrl: './weather-card.component.html',
styleUrls: ['./weather-card.component.scss']
})
export class WeatherCardComponent implements OnInit {
@Input() weather : Weather;
constructor() { }
ngOnInit(): void {
}
}
当前天气.component.html
<app-weather-card [weather]="weatherService.weather$ | async as weather" ></app-weather-card>
模板解析错误中的错误: 解析器错误:[weatherService.weather$ | 中的第 33 列出现意外标记“as”异步天气] 在 C:/Projects/projects-angular/weatherapp/src/app/current-weather/current-weather.component.html@0:29 ("]weatherService.weather$ | 异步天气" >") : C:/Projects/projects-angular/weatherapp/src/app/current-weather/current-weather.component.html@0:29
【问题讨论】:
-
你需要'as weather'吗?
-
好像错误来自模板,也为它做postcode。
-
为什么需要
as weather? -
因为它是一项服务,我有一个 observable 在应用程序中获取我从 api 获得的一些数据,相同的语法在前面的组件中有它,它工作正常没有问题
-
谢谢你,我可以通过删除 as 天气来修复它,并且它有效。非常感谢您的帮助。
标签: angular