angular 常用指令和方法
2015-06-26 13:59
621 查看
方法
angular.copy()
angular.extend(dst,src) //把src的所有属性复制到dst
指令
ng-cinclude //绑定模板
$sce.trustAsHtml
ng-bind-html //绑定html
服务
$injector
//IOC容器, $injector.get("serviceName"),$injector.get("$rootScope")
$animate.leave(element)
$httpProvider //可以改变$http 的默认行为
$route //会监视$location.url(),会是在map在route 中定义的url
angular.copy()
angular.extend(dst,src) //把src的所有属性复制到dst
var debug = true, Logger = { print: function(s) { return debug ? s : ‘’ } }; app.controller(‘ControllerOne’, [ ‘$scope’, function($scope) { // mixin $scope angular.extend($scope, Logger); // define our $scope angular.extend($scope, { myVar: 1, log: function() { this.print(this.myVar); } }); }]); app.controller(‘ControllerTwo’, [ ‘$scope’, function($scope) { // mixin $scope angular.extend($scope, Logger); // define our $scope angular.extend($scope, { myVar: 2, log: function() { this.print(this.myVar); } }); }]);
app.controller(‘ThingController’, [ ‘$scope’, function($scope) { // private var _thingOne = ‘one’, _thingTwo = ‘two’; // models angular.extend($scope, { get thingOne() { return _thingOne; }, set thingOne(value) { if (value !== ‘one’ && value !== ‘two’) { throw new Error(‘Invalid value (‘+value+‘) for thingOne’); }, get thingTwo() { return _thingTwo; }, set thingTwo(value) { if (value !== ‘two’ && value !== ‘three’) { throw new Error(‘Invalid value (‘+value+‘) for thingTwo’); } }); // methods angular.extend($scope, { // in HTML template, something like {{ things }} get things() { return _thingOne + ‘ ‘ + _thingTwo; } }); }]);
指令
ng-cinclude //绑定模板
$sce.trustAsHtml
ng-bind-html //绑定html
app.filter('to_trusted', ['$sce', function ($sce) { return function (text) { return $sce.trustAsHtml(text); }; }]); <p ng-bind-html="currentWork.description | to_trusted"></p>
var ngBindHtmlDirective = ['$sce', function($sce) { return function(scope, element, attr) { scope.$watch($sce.parseAsHtml(attr.ngBindHtml), function(value) { element.html(value || ''); }); }; }]; url:https://docs.angularjs.org/api/ng/service/$sce
服务
$injector
//IOC容器, $injector.get("serviceName"),$injector.get("$rootScope")
$animate.leave(element)
$httpProvider //可以改变$http 的默认行为
$route //会监视$location.url(),会是在map在route 中定义的url
相关文章推荐
- AngularJS 指令
- jquery操作angularjs对象
- AngularJS表达式
- AngularJS简单介绍
- jquery操作angularjs对象
- 工作积累(八)——AngularJS与单选框及多选框的双向动态绑定
- AngularJs 用户登录验证模块(demo)参考总结
- AngularJS+Servlet跨域问题
- luluzero的angularJs学习之路_angularJs示例代码
- angularjs 指令中动态编译的方法(适用于有异步请求的情况) 内嵌指令无效
- AngulaJS实战总结, 带你进入AngularJS世界(待续)
- 强强联合之jquery操作angularjs对象
- 【转载】AngularJs 指令directive之controller,link,compile
- [AngularJS] Extract predicate methods into filters for ng-if and ng-show
- angular 路由
- angular 路由
- AngularJS tips-2 初始篇
- AngularJS Routing Using UI-Router
- AngularJS tips-1 安装篇
- 关于angularjs的一些小知识点