控制台调试
angular.element($0).scope() $0~$4
angular.element($("#controllerId")).scope()
手动启动
angular.element(document).ready(function(){
//如果用以下方式可删除body的ng-app="MyApp"
angular.bootstrap(document.body, ['MyApp'])
});
用ng-if代替ng-show
ng-class以及ng-style通过判断赋值
ng-class="{'state-error':!data.isValid}"
<div ng-init="isSelected=true" ng-class="{true:'selected', false:''}[isSelected]">ngClass
</div>
ng-style="{ color: data.color=='' || data.name=='活' ? '#fff' : '#F03EF0' }"
整合underscore.js
var underscore = angular.module('underscore', []); underscore.factory('_', function() { return window._; //Underscore must already be loaded on the page }); var myApp = angular.module("MyApp", ["ngSanitize", "underscore"]); myApp.controller("TableCtrl", ["$scope", '_', function($scope, _) { var init = function(){ console.log(_.keys($scope)); }; init(); }]);
依赖注入
angualar.module('myModule', []).
config(['depProvider', function(depProvider){
...
}]).
factory('serviceId', ['depService', function(depService) {
...
}]).
directive('directiveName', ['depService', function(depService) {
...
}]).
filter('filterName', ['depService', function(depService) {
...
}]).
run(['depService', function(depService) {
...
}]);