Javascript 从包含ng的HTML访问父控制器

Javascript 从包含ng的HTML访问父控制器,javascript,angularjs,Javascript,Angularjs,我想从包含ng的html访问控制器中的函数,该html包含一个带有html模板的指令 也就是说,给定带有控制器的父html模板: <div ng-controller="profileCtrl"> <div ng-include src="profileContent"></div> </div> myview.html: $scope.profileContent = '/html/views/myview.html'; $scope.

我想从包含ng的html访问控制器中的函数,该html包含一个带有html模板的指令

也就是说,给定带有控制器的父html模板:

<div ng-controller="profileCtrl">
    <div ng-include src="profileContent"></div>
</div>
myview.html:

$scope.profileContent = '/html/views/myview.html';
$scope.test = 'This should show';
<my-directive></my-directive>
angular
    .module('myModule')
    .directive('myDirective', [function () {
        return {
            restrict: 'E',
            templateUrl: '/html/directives/myDirectiveTemplate.html',
            ...
{{test}} //should output "This should show"
<form ng-submit="$parent.updateProfile()">
    $scope.updateProfile = function() {
        console.log('updating profile'); //not called
myDirectiveTemplate.html:

$scope.profileContent = '/html/views/myview.html';
$scope.test = 'This should show';
<my-directive></my-directive>
angular
    .module('myModule')
    .directive('myDirective', [function () {
        return {
            restrict: 'E',
            templateUrl: '/html/directives/myDirectiveTemplate.html',
            ...
{{test}} //should output "This should show"
<form ng-submit="$parent.updateProfile()">
    $scope.updateProfile = function() {
        console.log('updating profile'); //not called
如何从MyChild指令访问$scope.test


myDirectiveTemplate.html:

$scope.profileContent = '/html/views/myview.html';
$scope.test = 'This should show';
<my-directive></my-directive>
angular
    .module('myModule')
    .directive('myDirective', [function () {
        return {
            restrict: 'E',
            templateUrl: '/html/directives/myDirectiveTemplate.html',
            ...
{{test}} //should output "This should show"
<form ng-submit="$parent.updateProfile()">
    $scope.updateProfile = function() {
        console.log('updating profile'); //not called
像这样试试

{{$parent.test}}

好的,太好了!然而,我实际上想从该父控制器中的函数的子指令调用
ng submit
上的函数<代码>$parent.test输出很好,但如果调用
updateProfile
,它将不会运行。看到上面了吗?你能提供一个弹片吗?阿尼克,找到我的问题了。我正在用手风琴包装我的指令表。这个手风琴捕获了其中的作用域,这意味着我需要执行$parent.$parent.ctrlFunction()来访问控制器中的函数。