您的位置:首页 > Web前端 > AngularJS

angularjs 笔记

2014-10-11 17:36 141 查看
控制台调试
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) {
...
}]);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: