在AngularJS指令中,我理解有两种方法来定义控制器.可以使用controller:选项将控制器定义为指令定义的一部分.或者,指令的视图templateURL:'someview.html'可以包含所需的控制器.任何人都可以解释这两个选项之间的差异以及使用哪个选项?
在指令内:
app.directive('myDirective', function() {
templateUrl: 'someview.html,
controller: 'MyController' ----> either here
});
Run Code Online (Sandbox Code Playgroud)
someview.html
<div ng-contoller='my-controller'> ----> or here
</div>
Run Code Online (Sandbox Code Playgroud)