依赖注入不再工作 ionic2
dependency injection not working anymore ionic2
依赖注入在 ionic 2 中不再起作用
import {Page, Platform, NavController} from 'ionic-framework/ionic';
import {Signup} from '../signup/signup';
import {Pass} from '../pass/pass'
@Page({
templateUrl: 'build/pages/login/login.html'
})
export class Login {
constructor(platform: Platform, nav: NavController){
}
goTosignup(){
this.nav.push(Signup)
}
}
这就是我正在做的事情,今天之前工作得很好,今天我在控制台中收到这个错误
./app/pages/login/login.js 中的错误
模块构建失败:语法错误:/Users/ondondacarrel/Desktop/code/code2/jobandgo/app/pages/login/login.js:意外令牌 (10:20)
8 | })
9 |导出 class 登录 {
10 | constructor(platform: Platform, nav: NavController){
| ^
11 |
12 | }
13 |
constructor(@Inject(NavController) nav: NavController) 也不起作用,如果有人能帮我解决这个问题
能否请您尝试使用@Inject(),如下所示:
import {Page, Platform, NavController} from 'ionic-framework/ionic';
import {Inject} from 'angular2/core';
import {Signup} from '../signup/signup';
import {Pass} from '../pass/pass'
@Page({
templateUrl: 'build/pages/login/login.html'
})
export class Login {
constructor(@Inject(Platform) platform: Platform, @Inject(NavController) nav: NavController){
}
goTosignup(){
this.nav.push(Signup)
}
}
这是一个与 typescript 参数修饰和 javascript 参数修饰相关的问题
import {Page, NavController} from 'ionic-framework/ionic';
import {Signup} from '../signup/signup';
import {Pass} from '../pass/pass'
@Page({
templateUrl: 'build/pages/login/login.html'
})
export class Login {
static get parameters() {
return [[NavController]];
}
constructor(nav){
this.nav = nav
}
gotoPage(){
this.nav.push(Signup)
}
}
依赖注入在 ionic 2 中不再起作用
import {Page, Platform, NavController} from 'ionic-framework/ionic';
import {Signup} from '../signup/signup';
import {Pass} from '../pass/pass'
@Page({
templateUrl: 'build/pages/login/login.html'
})
export class Login {
constructor(platform: Platform, nav: NavController){
}
goTosignup(){
this.nav.push(Signup)
}
}
这就是我正在做的事情,今天之前工作得很好,今天我在控制台中收到这个错误
./app/pages/login/login.js 中的错误 模块构建失败:语法错误:/Users/ondondacarrel/Desktop/code/code2/jobandgo/app/pages/login/login.js:意外令牌 (10:20) 8 | }) 9 |导出 class 登录 {
10 | constructor(platform: Platform, nav: NavController){ | ^ 11 | 12 | } 13 |
constructor(@Inject(NavController) nav: NavController) 也不起作用,如果有人能帮我解决这个问题
能否请您尝试使用@Inject(),如下所示:
import {Page, Platform, NavController} from 'ionic-framework/ionic';
import {Inject} from 'angular2/core';
import {Signup} from '../signup/signup';
import {Pass} from '../pass/pass'
@Page({
templateUrl: 'build/pages/login/login.html'
})
export class Login {
constructor(@Inject(Platform) platform: Platform, @Inject(NavController) nav: NavController){
}
goTosignup(){
this.nav.push(Signup)
}
}
这是一个与 typescript 参数修饰和 javascript 参数修饰相关的问题
import {Page, NavController} from 'ionic-framework/ionic';
import {Signup} from '../signup/signup';
import {Pass} from '../pass/pass'
@Page({
templateUrl: 'build/pages/login/login.html'
})
export class Login {
static get parameters() {
return [[NavController]];
}
constructor(nav){
this.nav = nav
}
gotoPage(){
this.nav.push(Signup)
}
}