无法解析StateService的所有参数

时间:2016-11-24 13:39:24

标签: angular ionic2

我正在尝试使用 Angular 2 with Ionic 2 开发应用程序而不是 NavController 我想尝试使用 ui-router-ng2 <进行路由< /强>

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();
    }

  }

}


我已从“ui-router-ng2”导入 StateService I got the error, Can't resolve all parameters for StateService:

请帮我整理这个问题。

1 个答案:

答案 0 :(得分:-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();
        });
    }
}