如何创建指令控制器?

我的问题是,我找不到任何关于此的官方文档。

https://docs.angularjs.org/guide/directive未注明建议

controller: ['$scope', function($scope) {

为什么我不能在$这里省略s,就像在link function(scope, elem, attrs) {controller: ['scope', function(scope) {将导致错误"Error: [$injector:unpr] Unknown provider: scopeProvider <- scope

这里的语法是什么?


一只甜甜圈
浏览 429回答 3
3回答

慕的地8271018

有关所谓的官方文档directive definition object可以在$ reference for $ compile中找到。的directive controller constructor function是注射用当地人$scope,$element,$attrs和$transclude。注入这些。因此,他们的确切拼写很重要。创建directive controller通道controller:function($scope) {}与创建通道相同controller:['$scope', function(scope) {}]。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript