Angularjs 在ui路径中。是否有可能获取该对象<;a>;请求是从它那里来的?
因为我用自己的名字请求页面(意思是:没有id) 我希望我对服务器的查询将基于id 而不是根据页面的名称。 因为这样的话,查询将是两次 我想输入控制器的id 所以我想在属性Angularjs 在ui路径中。是否有可能获取该对象<;a>;请求是从它那里来的?,angularjs,angular-ui-router,Angularjs,Angular Ui Router,因为我用自己的名字请求页面(意思是:没有id) 我希望我对服务器的查询将基于id 而不是根据页面的名称。 因为这样的话,查询将是两次 我想输入控制器的id 所以我想在属性数据页id 但我无法从状态中找到它 到元素中的属性数据 Ps 我看到它可以是doui-sref-active指令 使当前页的类处于“活动”状态 所以我想,如果有可能ui-route来识别按下的链接是什么 也许也有可能接受身份证 我将在对象中植入 这是我的控制器: $locationProvider.html5Mode({
数据页id
但我无法从状态中找到它
到
元素中的属性数据
Ps
我看到它可以是doui-sref-active
指令
使当前页的类处于“活动”状态
所以我想,如果有可能ui-route
来识别按下的链接是什么
也许也有可能接受身份证
我将在
对象中植入
这是我的控制器:
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
$stateProvider
.state('pages', {
url: '/:page',
templateProvider:['$templateRequest',
function($templateRequest){
return $templateRequest(BASE_URL + 'assets/angularTemplates/pages.html');
}],
controller: function($scope, $http){
if(window.content){ // Here the server sending json when if is it a first loading to the particular page and not coming from the home page
$scope.contentPage = window.content;
delete window.content;
}
else {
var pageID = 2; // Here I want to access an object attribute <a> to get the id
$http.get(BASE_URL + '?Angular_pageID=' + pageID)
.then(function(res){
$scope.contentPage = res.data;
});
}}
})
$locationProvider.html5模式({
启用:对,
requireBase:错误
});
$stateProvider
.state('页'{
url:“/:页面”,
templateProvider:[“$templateRequest”,
函数($templateRequest){
返回$templaterrequest(BASE_URL+'assets/angularTemplates/pages.html');
}],
控制器:函数($scope,$http){
if(window.content){//当if是第一次加载到特定页面而不是来自主页时,服务器发送json
$scope.contentPage=window.content;
删除window.content;
}
否则{
var pageID=2;//这里我想访问一个对象属性来获取id
$http.get(BASE_URL+'?Angular_pageID='+pageID)
.然后(功能(res){
$scope.contentPage=res.data;
});
}}
})
以下是我的HTML代码:
<ul class="nav nav-tabs nav-justified">
<li ui-sref-active="active"><a ui-sref='pages({page: ""})'>Home</a></li>
<li ng-repeat="menu in menus" ng-if="!$first" ui-sref-active="active"><a ui-sref='pages({page: menu.url })' data-id-page='{{menu.id}}'>{{menu.link}}</a></li>
</ul>
主页
- {{menu.link}
您能在href或sref属性中使用查询参数吗/:page?id
然后通过您的$stateParams
对象访问它?否。我试图以两种方式将它放入ui sref
的对象,但它给我带来了一个错误{{menu.link}
您不必在menu.id上使用花括号。看看这个例子:我终于成功地用id
执行了一个查询字符串。但是我更喜欢没有传输查询字符串的方式。。如果可能的话,我希望使用“ui url”,而目前还没有可以使用ng href的ui url(据我所知)。查看更新的plunk:并查看route1.html ng href链接。