angular 遇到的坑--小记1

本文详细介绍了AngularJS中directive指令的使用技巧,包括如何避免多个指令在同一元素上使用时的作用域冲突,解决ng-controller标签为空时的错误,以及正确注册自定义指令的方法。同时,还探讨了指令中controller的正确使用方式及常见错误。
  • 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不可以在指令中重新赋值会导致冲突问题,比如说scopeparentscope有问题

2015/11/20更新:Error: $injector:unprUnknown Provider 错误是angular module 多次声明问题。

angular.module(['commonServices'], []) 该模块只能声明一次
需要使用可以直接使用
 angular.module('commonServices').factory(...)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值