可通过API访问的服务器数据库中的slugs:
{slug: "john-smith",type: "user"}
{slug: "microsoft-technologies",type: "company"}
Run Code Online (Sandbox Code Playgroud)
场景1:用户视图和控制器:http:// localhost/john-smith
.state('user', {
url: '/:user',
templateUrl: 'partial-user.html',
controller: 'userCtrl'
})
Run Code Online (Sandbox Code Playgroud)
方案2:公司视图和控制器:http:// localhost/microsoft-technologies
.state('company', {
url: '/:company',
templateUrl: 'partial-company.html',
controller: 'companyCtrl'
})
Run Code Online (Sandbox Code Playgroud)
现在我想基于从API调用到服务器的slug做一个动态状态.
我写了一个虚构的代码.但我没有办法实现
// Example URL http://localhost/john-smith
.state('hybrid', {
// /john-smith
url: '/:slug',
templateUrl: function () {
return "partial-"+type+".html"
},
controllerProvider: function (rt) {
return type+'Controller'
},
resolove: {
type: function ($http, $stateParams) {
$http.get({
method: "GET",
url: "http://localhost/api/" + $stateParams.slug
}).success(function(response, status, headers, config){
//response …Run Code Online (Sandbox Code Playgroud) 我想根据我在angularjs bootstrap中定义的预设常量来更改与控制器关联的templateUrl.我无法弄清楚如何改变它.我已经尝试过UrlRouteProvider但是还没弄清楚如何从文件系统中拉出html.我被困在templateUrl上.
在下面的代码中,输出首先显示"svcc确实传递到第一个函数的console.out但是在templateUrl定义函数中,CONFIG是未定义的.
我愿意采取其他方式来做到这一点.
var app = angular.module('svccApp', [
'ui.router'
]);
var myConstant = {};
myConstant.codeCampType = "svcc";
app.constant("CONFIG", myConstant);
app.config(['$stateProvider', '$urlRouterProvider','CONFIG',
function ($stateProvider, $urlRouterProvider,CONFIG) {
console.log(CONFIG.codeCampType);
$stateProvider
.state('home', {
url: '/home',
//templateUrl: 'index5templateA.html', (THIS WORKS)
templateUrl: function(CONFIG) {
console.log('in templateUrl ' + CONFIG.codeCampType);
if (CONFIG.codeCampType === "svcc") {
return 'index5templateA.html';
} else {
return 'index5templateB.html';
}
},
controller: function ($state) {
}
});
}]);
Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我使用角度UI路由器.
我有当地人(英语和希伯来语)我的基本语言是英语.
这就是为什么我想要的语言是英语不要将参数添加到网址
例如:
http://example.com/Home希伯来语 - > http://example.com/he/
关于我们English - > http://example.com/about
http://example.com/he/about这可能吗 ?
这是我目前的代码
$stateProvider
.state('/', {
url: "/",
templateUrl: "Assets/app/templates/home.html",
controller: 'homeController'
})
.state('activity', {
url: "/activity",
templateUrl: "Assets/app/templates/gallery.html",
controller: 'galleryController'
})
.state('page', {
url: '/:pagename',
templateUrl: "Assets/app/templates/page.html",
controller: 'pageController'
});
Run Code Online (Sandbox Code Playgroud)