我想从 ng 包含的 html 访问 Controller 中的函数,其中包含带有 html 模板的指令。
含义,给定带有 Controller 的父 html 模板:
<div ng-controller="profileCtrl">
<div ng-include src="profileContent"></div>
</div>
个人资料Ctrl:
$scope.profileContent = '/html/views/myview.html';
$scope.test = 'This should show';
myview.html:
<my-directive></my-directive>
我的指令:
angular
.module('myModule')
.directive('myDirective', [function () {
return {
restrict: 'E',
templateUrl: '/html/directives/myDirectiveTemplate.html',
...
myDirectiveTemplate.html:
{{test}} //should output "This should show"
如何从子 myDirective 访问 $scope.test?
<小时/>myDirectiveTemplate.html:
<form ng-submit="$parent.updateProfile()">
个人资料Ctrl:
$scope.updateProfile = function() {
console.log('updating profile'); //not called
最佳答案
尝试这样
{{$parent.test}}
关于javascript - 从 ng 包含的 HTML 访问父 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31645097/