Javascript Angularjs指令从父级调用函数';s控制器
因为我的问题只是代码中缺少的一个单词,所以我将编写实现它的方法 我认为它可能会帮助其他学习者 文件列表:Javascript Angularjs指令从父级调用函数';s控制器,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,因为我的问题只是代码中缺少的一个单词,所以我将编写实现它的方法 我认为它可能会帮助其他学习者 文件列表: app.js mycontroller.js page.html mydirective.html mydirections.js 您的app.js正在使用路由提供程序显示您的视图。在本例中,您只有一个视图,即page.html。此页面由mycontroller.js控制 您希望您的page.html显示几个指令,每个指令在设计上都非常不同,因此您将模板放在了mydirections.h
- app.js
- mycontroller.js
- page.html
- mydirective.html
- mydirections.js
app.controller('mycontroller', function ($scope) {
$scope.sendAlert = function () {
alert("It works !");
}
});
现在您正在定义指令mydirective.html。我们将为示例添加一个简单的按钮
... your design
<button ng-click="callFunction()" type="button">Call the function</button>
... end of your design
现在,您可以在page.html中添加该指令。它是被定义的。不要忘记添加函数;)
别忘了添加并包含项目中的所有文件,现在它就可以工作了 您是否忘记通过scope
test=“test”
我花了好几个小时看这段代码,我错过了这段代码。好笑。谢谢你,我的朋友。
app.directive('test', function() {
return {
restrict: 'E',
templateUrl: 'mydirectives.html',
scope : {
callFunction: "=call",
}
};
});
<test call="callFunction"></test>