我创建了一个服务,在离子3中有一个名为“code”的参数我很困惑如何在离子4中更改相同的代码?
你如何抓住代码并将其推入离子4的火焰基地?
我有类似的服务,我在离子4,但我不知道如何拉它。我尝试了一堆方法,但它不起作用。
submitQuiz(questions: Questions){
var code = this.navParams.get('code');
console.log(code);
for (var z = 0; z < this.i; z++) {
console.log(questions[z]);
this.questions$.push({
code: code,
question: questions[z]
});
}
这是我的服务
export interface Quiz {
code: String;
}
export interface Users {
email: String;
password: String;
nickname: String;
}
export interface Questions{
code: String;
question: any;
}
试试这种方式:
import { ActivatedRoute } from '@angular/router';
constructor(
private route: ActivatedRoute,
...
) { }
submitQuiz(questions: Questions) {
this.route.params.subscribe((params) => {
const code = params.code;
console.log(code);
for (let z = 0; z < this.i; z++) {
console.log(questions[z]);
this.questions$.push({
code: code,
question: questions[z]
});
}
});
}
可以使用forEach()改进循环
submitQuiz(questions: Questions) {
this.route.params.subscribe((params) => {
const code = params.code;
console.log(code);
questions.forEach((question) => {
this.questions$.push({
code: code,
question: question
});
});
});
}