Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度ui路由器ui sref重定向回调用页面,即使目标页面正确呈现_Angularjs_Angular Ui Router - Fatal编程技术网

Angularjs 角度ui路由器ui sref重定向回调用页面,即使目标页面正确呈现

Angularjs 角度ui路由器ui sref重定向回调用页面,即使目标页面正确呈现,angularjs,angular-ui-router,Angularjs,Angular Ui Router,我是个新手,必须在这里做些傻事,我一辈子都搞不懂。提前感谢您的帮助 简而言之,我有3个页面,当直接通过浏览器中的地址栏访问它们时,它们都能正确加载: #/communities #/companies #/companies/:id 我使用ui router定义了公司状态,如下所示: //companies.js file: .config(function config( $stateProvider ) { $stateProvider .state( 'companies', {

我是个新手,必须在这里做些傻事,我一辈子都搞不懂。提前感谢您的帮助

简而言之,我有3个页面,当直接通过浏览器中的地址栏访问它们时,它们都能正确加载:

#/communities
#/companies
#/companies/:id
我使用ui router定义了公司状态,如下所示:

//companies.js file:
.config(function config( $stateProvider ) {
$stateProvider
    .state( 'companies', {
        url: '/companies',
        views: {
            "main": {
                templateUrl: 'companies/companies.tpl.html'
        }
    },
data:{ pageTitle: '' }
  });
})

//companies.detail.js file:
.config(function config( $stateProvider ) {
$stateProvider
    .state( 'companies.detail', {
        url: '/:id',
        views: {
            //use @ to force use of parent ui-view tag
            "main@": {
                templateUrl: 'companies/companies.detail/companies.detail.tpl.html'
        }
    },
data:{ pageTitle: '' }
  });
})

.controller('CompanyDetailCtrl', ['CompaniesService', '$stateParams',
    function(CompaniesService, $stateParams) {

    alert($stateParams.id); //this fires when I navigate to page briefly

    var _this = this; //need to get better approach for this (ideally remove)
    _this.hoas = [];

    CompaniesService.getCompanyHoas($stateParams.id).then(function(response) {
        _this.hoas = response;
    });

}])
;

//communities.tpl.html calling page snippet:
<a ui-sref="companies.detail({id:hoa.company.id})">{{hoa.company.name}}</a>
//companys.js文件:
.config(函数配置($stateProvider){
$stateProvider
.国家(‘公司’{
url:“/公司”,
观点:{
“主要”:{
templateUrl:'companys/companys.tpl.html'
}
},
数据:{pageTitle:''}
});
})
//companys.detail.js文件:
.config(函数配置($stateProvider){
$stateProvider
.州('companys.detail'{
url:“/:id”,
观点:{
//使用@强制使用父ui视图标记
“主要内容”:{
templateUrl:'companys/companys.detail/companys.detail.tpl.html'
}
},
数据:{pageTitle:''}
});
})
.controller('CompanyDetailCtrl',['companyeservice','$stateParams',',
函数(CompanyService,$stateParams){
警报($stateParams.id);//当我快速导航到页面时,会触发此警报
var _this=this;//需要更好的方法(理想情况下删除)
_this.hoas=[];
CompaniesService.getCompanyHoas($stateParams.id).then(函数(响应){
_this.hoas=响应;
});
}])
;
//communities.tpl.html调用页面片段:
{{hoa.company.name}
当我将鼠标悬停在浏览器(即:“companys/223”)上时,URL被正确创建,companys/223页面被正确导航到,但仅在一瞬间,然后重定向回调用页面。该页面在浏览器历史记录中被捕获(因此我可以返回并停留在它上面,它工作得很好),但当我单击此链接时,它总是重定向回


我错过了什么???我快死了。谢谢你的帮助。:)

状态总是重定向回调用页的原因是我将ui sref包装在指向调用页的父ui sref元素中:

<a ui-sref="companies" class="list-group-item" 
ng-click="list.selectCommunity(community)" 
ng-switch on="list.isSelected(community)"
ng-class="{'active': list.isSelected(community)}" >
    <div ng-switch-when="true">
        <div class="table-responsive">
            <table class="table">
                ...
                    <td class="hidden-xs"><a ui-sref="companies.detail({id:hoa.company.id})">{{hoa.company.name}}</a></td>
                ...
            </table>
        </div>
    </div>
</a>

...
{{hoa.company.name}
...
我通过将第一行更改为:

<a href="#" class="list-group-item" ...

状态总是重定向回调用页的原因是我将ui sref包装在指向调用页的父ui sref元素中:

<a ui-sref="companies" class="list-group-item" 
ng-click="list.selectCommunity(community)" 
ng-switch on="list.isSelected(community)"
ng-class="{'active': list.isSelected(community)}" >
    <div ng-switch-when="true">
        <div class="table-responsive">
            <table class="table">
                ...
                    <td class="hidden-xs"><a ui-sref="companies.detail({id:hoa.company.id})">{{hoa.company.name}}</a></td>
                ...
            </table>
        </div>
    </div>
</a>

...
{{hoa.company.name}
...
我通过将第一行更改为:

<a href="#" class="list-group-item" ...

状态总是重定向回调用页的原因是我将ui sref包装在指向调用页的父ui sref元素中:

<a ui-sref="companies" class="list-group-item" 
ng-click="list.selectCommunity(community)" 
ng-switch on="list.isSelected(community)"
ng-class="{'active': list.isSelected(community)}" >
    <div ng-switch-when="true">
        <div class="table-responsive">
            <table class="table">
                ...
                    <td class="hidden-xs"><a ui-sref="companies.detail({id:hoa.company.id})">{{hoa.company.name}}</a></td>
                ...
            </table>
        </div>
    </div>
</a>

...
{{hoa.company.name}
...
我通过将第一行更改为:

<a href="#" class="list-group-item" ...

状态总是重定向回调用页的原因是我将ui sref包装在指向调用页的父ui sref元素中:

<a ui-sref="companies" class="list-group-item" 
ng-click="list.selectCommunity(community)" 
ng-switch on="list.isSelected(community)"
ng-class="{'active': list.isSelected(community)}" >
    <div ng-switch-when="true">
        <div class="table-responsive">
            <table class="table">
                ...
                    <td class="hidden-xs"><a ui-sref="companies.detail({id:hoa.company.id})">{{hoa.company.name}}</a></td>
                ...
            </table>
        </div>
    </div>
</a>

...
{{hoa.company.name}
...
我通过将第一行更改为:

<a href="#" class="list-group-item" ...