【发布时间】:2015-07-27 12:47:51
【问题描述】:
我想从包含 ng 的 html 访问控制器中的函数,该 html 包含带有 html 模板的指令。
含义,给定带有控制器的父 html 模板:
<div ng-controller="profileCtrl">
<div ng-include src="profileContent"></div>
</div>
profileCtrl:
$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()">
profileCtrl:
$scope.updateProfile = function() {
console.log('updating profile'); //not called
【问题讨论】:
标签: javascript angularjs