augular.js的directive指令,多个在同一个指令。都需要隔离作用域。否则会报错。ng-controller标签不能为空。为空报Badly formed controller string ‘{0}’. Must match __name__ as __id__ or __name__.错误
ng-controller 子继承父scope域,parent scope 参数设置model类型 。
eg. 双向数据绑定
parent controller
$scope.tbodys =[{...},{...}]
children controller
$scope.parentTbodys = $scope.tbodys;
eg. 单项数据绑定,继承parent,但parent不能修改children $scope
parent controller
$scope.tbodys =[{…},{…}]
children controller
scope.parentTbodys=scope.tbodys;
directive 注册的标签名称如果是含大写的字符串需要使用中划线进行分割。参数也是一样的,如果使用骆驼式命名,在html中需要使用中划线进行分割
eg.
//angular.js
app.directive(‘maDatagrid’,maDatagridDirective);
directive 匿名的controller不可以在指令中重新赋值会导致冲突问题,比如说scope继承parentscope有问题
2015/11/20更新:Error: $injector:unprUnknown Provider 错误是angular module 多次声明问题。
angular.module(['commonServices'], []) 该模块只能声明一次
需要使用可以直接使用
angular.module('commonServices').factory(...)

本文详细介绍了AngularJS中directive指令的使用技巧,包括如何避免多个指令在同一元素上使用时的作用域冲突,解决ng-controller标签为空时的错误,以及正确注册自定义指令的方法。同时,还探讨了指令中controller的正确使用方式及常见错误。
1258

被折叠的 条评论
为什么被折叠?



