1. 把控制器中与视图无关的逻辑都移到"服务(service)"中
2. 新手常犯错误
$routeProvider.when(‘/workout‘, { templateUrl: ‘partials/workout.html‘, controller: ‘WorkoutController‘ });
3. 本质上,当写directive时令时。当我们设置了link参数,实际上是创建了一个postLink() 链接函数,以便compile() 函数可以定义链接函数。编译函数(compile)负责对模板DOM进行转换。 链接函数(link)负责将作用域和DOM进行链接。
.... compile: function compile(tElement, tAttrs, transclude) { return { pre: function preLink(scope, iElement, iAttrs, controller) { ... }, post: function postLink(scope, iElement, iAttrs, controller) { ... } } }, link: function postLink(scope, iElement, iAttrs) { ... } ...
个人理解compile函数的功能更强。
详情内容:[译]ng指令中的compile与link函数解析
4. 使用ng-repeat指令,为防止重复值发生的错误。加上track by $index。
<li ng-repeat="i in ctrl.list track by $index">{{ i }}</li>
5. 关于向父子controller中传递内容。
原文:http://www.cnblogs.com/mafeifan/p/5210602.html