2016-11-24 90 views
1

我試圖開發使用角2應用程序與離子2和替代NavController我想嘗試用UI的路由器NG2路由。無法解決所有參數的StateService

Login.ts:

import { Component } from '@angular/core'; 
import { NavController, MenuController } from 'ionic-angular'; 

import { AlertController } from 'ionic-angular'; 

import { StateService } from "ui-router-ng2"; 

import { DashboardPage } from '../dashboard/dashboard'; 

@Component({ 
    selector: 'page-login', 
    templateUrl: 'login.html', 
    providers: [StateService] 
}) 

export class LoginPage { 

    username: string; 
    password: string; 

    constructor(public navCtrl: NavController, public menu: MenuController, public alertCtrl: AlertController, public state: StateService) { 

    this.menu.enable(false, 'sidenav') 

    } 

    login() { 

    if (this.username == "admin" && this.password == "admin") { 
     // this.navCtrl.setRoot(DashboardPage, { username: this.username }); 
     this.state.go(DashboardPage); 
    } else { 
     let alert = this.alertCtrl.create({ 
     title: 'Incorrect Credentials!', 
     subTitle: 'Your username and password are incorrect. Hint: admin', 
     buttons: ['Login Again'] 
     }); 
     alert.present(); 
    } 

    } 

} 


我已經進口的StateService從 「UI-路由器NG2」。 I got the error, Can't resolve all parameters for StateService:

請幫我分揀這個問題。

+0

你有'UIRouterModule.forRoot()'在你的bootstrap? –

+0

任何人已經解決了這個問題呢? – Rezoan

回答

-1

我有同樣的問題,我在我的服務之前通過@Injectable()解決了它。

就像是:

import {Http} from '@angular/http'; 
import {Observable} from 'rxjs/Observable'; 
import {Injectable} from '@angular/core'; 

@Injectable() 
export class StatService { 
    private ressourceInterneUrl = 'api/interne/stat'; 

    constructor(private http: Http) {} 

    addStatValues (viewName: string): Observable <any> { 
     return this.http.get(`${this.ressourceInterneUrl}/${viewName}`).map((res: any) => { 
      return res.json(); 
     }); 
    } 
} 
+0

一個完整的答案必須帶有一個完整的代碼示例,並解釋*爲什麼,和/或你的答案如何解決問題*。就目前而言,如果作爲評論**,您的答案會更好**,並可能被*低質量評審*系統刪除。 – Frits

相關問題