gpt4 book ai didi

javascript - 在应用程序初始化后添加 Angular ionic View 和路由

转载 作者:行者123 更新时间:2023-11-30 00:31:09 25 4
gpt4 key购买 nike

我对 Angular JS 有点陌生。我将它与 Ionic 和 Phonegap 一起使用来创建移动应用程序。此应用程序具有由网络服务器注入(inject)到应用程序中的 View 。

因此,我需要注入(inject) ionic html 标记 View 并以某种方式用 Angular 编译它们,并将这些新添加的 View 链接到路由定义。这是我到目前为止所做的 [inside app.config]:

app.stateProvider = $stateProvider; 

然后 [inside app.run] :

app.stateProvider.state('side-menu8', {
url: '/menu2',
templateUrl: 'side-menu8.html'
});
$state.go('side-menu8');

side-menu8.html 模板脚本标记被插入到 index.html 页面中。我这样做是为了测试状态是否在配置过程之外注册。该应用程序当前确实注册了附加状态并成功重定向到模板。我的问题是,我将如何添加一个动态服务来获取 View 和数据,将其注入(inject) index.html View 并注册其他状态?

最佳答案

配置设置应该始终在配置阶段完成,只是你不能从 app.run 注册路由,你必须在 app.config 中进行,当你想实现动态分页时,你可以向你声明的 url 添加一个参数,并在此基础上动态呈现你的模板

代码

app.config(["$stateProvider", function($stateProvider) {
$stateProvider.state('side-menu', {
url: '/menu/:id',
templateUrl: function($stateParams){
return 'side-menu'+ $stateParams.id +'.html'; //this will fetch template dynamically
}
});
//you could also add state here
}]);

关于javascript - 在应用程序初始化后添加 Angular ionic View 和路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29447323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com