使用UrlResolver发布组件相对URL的问题 - 没有Token Application Packages根URL的提供程序

时间:2016-12-22 21:22:36

标签: angular angular2-routing

我正在尝试解析图片网址:

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的构造函数注入导致错误:

image

app.component.html代码

 <img [src]="resolvePath('Logo.jpg')" alt="Logo" width="50" height="50">

为什么构造函数注入错误,我应该在提供程序中添加任何内容吗?

0 个答案:

没有答案