亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Angular DI錯誤 - EXCEPTION:無法解析所有參數

Angular DI錯誤 - EXCEPTION:無法解析所有參數

小怪獸愛吃肉 2019-08-06 14:49:30
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 回答

?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

從直接聲明它的文件中導入它而不是桶。

我不知道究竟是什么導致了這個問題,但我看到它多次提到(可能是某種循環依賴)。

它也應該通過改變桶中出口的順序來修復(不知道細節,但也被提到)


查看完整回答
反對 回復 2019-08-06
?
呼如林

TA貢獻1798條經驗 獲得超3個贊

除了之前給出的答案之外,當您的注射服務缺少實際@Injectable()裝飾器時,似乎也會拋出此錯誤。因此,在調試循環依賴項和導入/導出的順序之前,請檢查您的服務是否實際已@Injectable()定義。

這適用于當前的Angular最新版Angular 2.1.0。


查看完整回答
反對 回復 2019-08-06
  • 3 回答
  • 0 關注
  • 637 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號