Angularjs 如何在指令';什么样的模板?

Angularjs 如何在指令';什么样的模板?,angularjs,angularjs-directive,attributes,angularjs-scope,Angularjs,Angularjs Directive,Attributes,Angularjs Scope,从本质上说,我希望这能起作用: myApp.directive('myDirective', function() { var someObj = {"shout": "Yodelayheehoo"}; return { restrict: 'E', template: "<my-special-directive my-obj="someObj"></my-special-directive>" }

从本质上说,我希望这能起作用:

myApp.directive('myDirective', function() {
     var someObj = {"shout": "Yodelayheehoo"};

     return {
          restrict: 'E',
          template: "<my-special-directive my-obj="someObj"></my-special-directive>"
     }
});
myApp.directive('myDirective',function(){
var someObj={“shout”:“Yodelayheehoo”};
返回{
限制:'E',
模板:“”
}
});
我希望
mySpecialDirective
接收在
myDirective
中定义的对象,但它不是


什么样的语法(如果有的话)可以实现这一点?

当您制定指令时,您可以创建一个链接函数(制定指令的所有逻辑),该函数的第一个参数是指令的范围。然后,您需要将变量添加到该范围中,以便在指令内部进行访问

var-app=angular.module('asd',[]);
app.directive('myDirective',function(){
var someObj={“shout”:“Yodelayheehoo”};
返回{
限制:'E',
模板:“{someObj}}”,
链接:功能(范围){
scope.someObj=someObj;
}
}
});


需要在链接到workMm的函数中添加到指令的作用域,可能另一个指令没有转移并删除内容,请将模板中的“我的特殊指令”更改为div,然后查看是否显示该值