Javascript AngularJS:嵌套元素时,指令无权访问控制器

Javascript AngularJS:嵌套元素时,指令无权访问控制器,javascript,angularjs,angular-ui,Javascript,Angularjs,Angular Ui,问题:当元素在某些页面上使用时,为什么我的simple指令不能访问它的控制器 附加信息:该指令在主页上起作用。我无法对其使用我的指令的HTML使用ui视图调用,如下所示 <div ui-view></div> HTML不起作用: HTML工作正常 我看到您使用了不同的模块,这就是为什么一个模块不知道另一个模块指令。您应该使用相同的模块 比如: js: 像往常一样使用html: <postcard-link></postcard-link> 谢

问题:当元素在某些页面上使用时,为什么我的simple指令不能访问它的控制器

附加信息:该指令在主页上起作用。我无法对其使用我的指令的HTML使用ui视图调用,如下所示

<div ui-view></div>
HTML不起作用:

HTML工作正常


我看到您使用了不同的模块,这就是为什么一个模块不知道另一个模块指令。您应该使用相同的模块

比如:

js:

像往常一样使用html:

<postcard-link></postcard-link> 

谢谢你的评论。我还是不明白,虽然。。。ctrl是控制器别名,对吗?在指令中,我将LinkController指定为ctrl和{{ctrl.ownerObj.user}。我应该在哪里更改别名?“链接控制器”中的语法错误。“功能”后缺少花括号谢谢-从复制粘贴到SO的打字错误!指令可以工作,只是不在我需要的地方…嘿-如果我理解正确,你是说声明前面的变量在控制器和指令中是不同的?通常你是对的。在本例中,所有模块都集中在一个应用程序下,如angular.module'Positcars'、['Positcars.Controller'、'Positcars…“],对于所有相关子模块。是的,模块依赖项在同一位置注入单个模块,否则会彼此隔离。如果项目规模是小型或中型,单个模块更好。您还可以在控制器或指令中注入自定义服务或工厂依赖项。谢谢,但我认为这并不能解决问题。问题不在于指令不起作用或无法访问控制器。问题是在某个视图中有东西正在中断访问。谢谢!我仍然有同样的问题-我不认为这与没有导入的模块有关,因为它是导入的,而且我在其他指令方面也有问题。
var PostcardsControllers = angular.module('postcards.controllers', ['postcards.factories', 'postcards.services']);

PostcardsControllers.controller('postcardLinkController', [function ()
    this.ownerObj = {
        "user": 'test_owner',
        "pointofthis": 'inane testing'
    }
}]);
<div ng-controller="DashboardAccountController as infoCtrl" class="container full-container">

<!------------------ DIRECTIVE REFERENCE HERE -------->        
<postcard-link></postcard-link>

    <h1>
        <small>Welcome</small>
        <username-text></username-text>
    </h1>
    <img ng-show="infoCtrl.user.member_profile.profile_image" ng-src="{{ infoCtrl.user.member_profile.profile_image }}"
         style="min-height:100px;height:100px;" alt='profileImage'/>
    <button type="button" class="btn btn-link col-md-offset-2" ng-click="infoCtrl.loadPage()">Modify Account</button>
    <div class="row">
...
<ng-include src="'static/app/carousel/_carousel.html'"></ng-include>

<postcard-link></postcard-link>
<div class="container">
    <section style="text-align: center">
        <h1>How It Works</h1>
var app = angular.module('postcards', []);//add dependencies in []

app.directive('postcardLink', function () {
    return {
        restrict: "AE",
        template: '<div class="well">{{ ctrl.ownerObj.user }}</div>',
        controller: 'postcardLinkController as ctrl'
    }
});

app.controller('postcardLinkController', [function () {
    this.ownerObj = {
        "user": 'test_owner',
        "pointofthis": 'inane testing'
    }
}]);
<postcard-link></postcard-link>