ui路由器中通过templateUrl的角度传递参数 [英] Angular passing parameters through templateUrl in ui-router

查看:79
本文介绍了ui路由器中通过templateUrl的角度传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angularsails来构建一个Web应用程序,其中每个用户都有自己的应用程序,因此要显示其公开个人资料,我必须使用不同的模板.我正在使用ui-router,如果我可以将传递给route url的id传递给templateUrl字段,我可以轻松解决此问题,那么有没有办法做到这一点?

I am using angular and sails to build a web app, in which each user have their own them so to display their public profile I have to use different templates. I am using ui-router and if I can pass id passed to the route url to templateUrl field I can solve this problem easily, so is there a way to do that ??

app.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/');
  $stateProvider
    .state('profile', {
      abstract: true,
      url: '',
      templateUrl: domain + "/profile/master",
      controller: 'profileController'
    })
    .state('profile.user', {
      url: '/user/:id',
      templateUrl: domain + '/angular/profile/:id',
      controller: 'privateProfileController'
    });
});

推荐答案

源链接

.state('contacts.detail', {
  url: '/{contactId}',
  views: {
    'menu': {
        templateUrl:
                 function (stateParams){
                    return '/partials/contacts.detail' + stateParams.contactId + '.html';
            }
    }
  }
})

这篇关于ui路由器中通过templateUrl的角度传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆