问题描述
在我的角度应用程序,我有以下航线结构:
In my Angular app, I have the following route structure:
.state('mapping', {
url: '/mapping',
templateUrl: 'app/components/mapping/mapping.html',
controller: 'MapCtrl as map',
abstract: true,
authenticate: true
})
.state('mapping.all', {
url: '',
templateUrl: 'app/components/mapping/partials/all.html',
authenticate: true
})
.state('mapping.project', {
url: '/:projectName',
templateUrl: 'app/components/mapping/partials/project.html',
controller: 'ProjectCtrl as proj',
authenticate: true
})
在访问映射
状态, mapping.all
默认加载的。它基本上示出其中链接到mapping.project状态项目的清单,因为这样的:
When accessing the mapping
state, mapping.all
loads by default. It basically shows a list of projects which link to the mapping.project state, as such:
<a ui-sref="mapping.project({projectId: project.id, projectName: project.name})">...</a>
我要叫 ProjectCtrl
当我访问 mapping.project
以加载必要的数据,但它甚至从来没有被加载。在下面的代码片段仅包括相关数据显示,警报
消息从来没有弹出:
I want to call the ProjectCtrl
when I access mapping.project
in order to load the necessary data, but it never even gets loaded. In the snippet below which includes only relevant data, the alert
message never pops up:
angular
.module('watera')
.controller('ProjectCtrl', Controller);
Controller.$inject = ['$stateParams', 'UserFactory', 'ProjectFactory'];
function Controller($stateParams, UserFactory, ProjectFactory) {
var proj = this;
activate();
function activate() {
alert('1');
}
}
JS文件是正确链接并且所述控制器被正确地命名。在&LT;格UI的视图&gt;&LT; / DIV&GT;
元素放置在 mapping.html
,如下图所示
The js file is correctly linked and the controller is named correctly. The <div ui-view></div>
element is placed within mapping.html
, as seen below:
<div id="ribbon" class="no-print">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<strong>Mapping</strong>
<p class="text-muted">In this section...</p>
</div>
</div>
</div>
</div>
<div ui-view></div>
这是为什么控制器不装?
Why is this controller not loading?
编辑:它变得怪异,我切换的结构:
It gets weirder, I switched the structure to:
.state('mapping', {
url: '/mapping',
templateUrl: 'app/components/mapping/mapping.html',
abstract: true,
authenticate: true
})
.state('mapping.all', {
url: '',
templateUrl: 'app/components/mapping/partials/all.html',
controller: 'MapCtrl as map',
authenticate: true
})
.state('mapping.project', {
url: '/:projectName',
templateUrl: 'app/components/mapping/partials/project.html',
controller: 'ProjectCtrl as proj',
authenticate: true
})
虽然 MapCtrl
一直工作正常, ProjectCtrl
还没有。
And while MapCtrl
keeps working correctly, ProjectCtrl
still doesn't.
推荐答案
发现问题......有这个项目 ProjectCtrl
的两个实例:
Found the issue... There were two instances of ProjectCtrl
in this project:
显然,这会导致某种无声的冲突,因为当时绝对没有控制台错误。由于二审还挂在 index.html的
的之后的,我想加载,它可能是简单地更换正确的版本之一。调试的噩梦。
Apparently, this causes some sort of silent conflict because there was absolutely no console error. Since the second instance was also linked on index.html
, after the one that I wanted to load, it was probably simply replacing the correct version. Debugging nightmare.
现在固定的。
这篇关于角UI路由器:孩子状态控制器不获取调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!