我正在开发一个带有微信登录功能的APP。获得微信批准后,它会调用我的 NativeScript APP 的自定义活动。我得到了正确的响应,但如何在进行一些验证后移动到主页的另一个页面。我正在使用 NativeScript + Angular。
getJSON("https://api.weixin.qq.com/sns/oauth2/access_token?appid=ID&secret=SECRET&code=" + res.code + "&grant_type=authorization_code").then((res) => {
console.dir(res);
// ===> here I want navigation
}, err => {
console.dir(err);
})
我试过这样:
frame.topmost().navigate("src/app/login/login.component");
但得到错误:
JS:未处理的承诺拒绝:无法设置未定义的属性“_moduleName”;区域: ; 任务: Promise.then ;值:TypeError:无法设置未定义的属性“_moduleName” TypeError:无法设置未定义的属性“_moduleName”
请给我一些建议。提前致谢 :)
从 Activity 回调中触发一个事件,例如
import { android } from "tns-core-modules/application";
...
public onResp(res: com.tencent.mm.opensdk.modelbase.BaseResp) {
console.log("onResp");
console.dir(res);
androidApp.notify(<AndroidActivityEventData>{ eventName: 'wxapiresponse', object: android, activity: this });
}
在 app 组件中,监听事件
export class AppComponent implements OnInit {
constructor(private ngZone: NgZone, private routerExtensions: RouterExtensions) {}
ngOnInit() {
application.android.on('wxapiresponse', this.wxApiResponse, this);
}
wxApiResponse() {
// making sure the event callback runs inside Angular zone
this.ngZone.run(() => {
this.routerExtensions.navigate(...);
});
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句