我正在尝试解析图片网址:
app.module.ts代码
import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { AppComponent } from "./app.component";
import { routing, appRoutingProviders } from "./app.routing";
import { Routes, RouterModule } from "@angular/router";
import { UrlResolver } from '@angular/compiler';
const routes: Routes = [
];
@NgModule({
imports: [
BrowserModule,
routing,
RouterModule.forRoot(routes, { useHash: true })
],
declarations: [
AppComponent
],
providers: [
appRoutingProviders, UrlResolver
],
bootstrap: [AppComponent]
})
export class AppModule {
}
app.component.ts代码:
import { Component } from "@angular/core";
import { Router } from "@angular/router";
import { UrlResolver } from '@angular/compiler';
@Component({
moduleId: module.id,
selector: "my-app",
templateUrl: "app.component.html"
})
export class AppComponent {
constructor(private urlResolver: UrlResolver) { }
public resolvePath(path) {
return this.urlResolver.resolve(module.id, path);
}
}
我正在提供UrlResolver,但UrlResolver的构造函数注入导致错误:
app.component.html代码
<img [src]="resolvePath('Logo.jpg')" alt="Logo" width="50" height="50">
为什么构造函数注入错误,我应该在提供程序中添加任何内容吗?