我有以下代码。我读过这个指令可以从它们的父范围继承对象和变量。我有一个带有子指令的控制器,但我似乎无法在我的指令中获得我的$scope.title
。AngularJS控制器变量未传递给子指令
这是为什么?
https://plnkr.co/edit/h4YlRPa5ZWQkwPZ3isjZ?p=preview
var mod = angular.module('myApp', []);
mod.controller('myControl', controlFunc).directive('myDirec', direcFunc);
function controlFunc($scope){
$scope.title = "John Smith";
}
function direcFunc(){
return {
restrict: 'E',
template: '<h1>' + $scope.title + '</h1>'
};
}
你期望在重击者身上看到什么?我看到“约翰史密斯”。 – Matt