Angular DI錯誤 - EXCEPTION:無法解析所有參數我在Angular中構建了一個基本的應用程序,但是我遇到了一個奇怪的問題,我不能將服務注入到我的一個組件中。它注入了我創建的其他三個組件中的任何一個。首先,這是服務:import { Injectable } from '@angular/core';@Injectable()export class MobileService {
screenWidth: number;
screenHeight: number;
constructor() {
this.screenWidth = window.outerWidth;
this.screenHeight = window.outerHeight;
window.addEventListener("resize", this.onWindowResize.bind(this) )
}
onWindowResize(ev: Event) {
var win = (ev.currentTarget as Window);
this.screenWidth = win.outerWidth;
this.screenHeight = win.outerHeight;
}}它拒絕使用的組件:import { Component, } from '@angular/core';import { NgClass } from '@angular/common';import { ROUTER_DIRECTIVES } from '@angular/router';import {MobileService} from '../';@Component({
moduleId: module.id,
selector: 'pm-header',
templateUrl: 'header.component.html',
styleUrls: ['header.component.css'],
directives: [ROUTER_DIRECTIVES, NgClass],})export class HeaderComponent {
mobileNav: boolean = false;
constructor(public ms: MobileService) {
console.log(ms);
}}我在瀏覽器控制臺中遇到的錯誤是:EXCEPTION:無法解析HeaderComponent的所有參數:(?)。我在bootstrap函數中有服務,所以它有一個提供程序。我似乎能夠毫無問題地將它注入我的任何其他組件的構造函數中。
- 3 回答
- 0 關注
- 637 瀏覽
添加回答
舉報
0/150
提交
取消