2016-11-24 47 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

相关问题