Angualr 1.4:

.directive('counter', function counter() {
return {
scope: {},
   restrict: 'EA',
transclude: true,
bindToController: {
count: '='
},
controller: function () {
function increment() {
this.count++;
}
function decrement() {
this.count--;
}
this.increment = increment;
this.decrement = decrement;
},
controllerAs: 'counter',
template: [
'<div class="todo">',
'<input type="text" ng-model="counter.count">',
'<button type="button" ng-click="counter.decrement();">-</button>',
'<button type="button" ng-click="counter.increment();">+</button>',
'</div>'
].join('')
};
});

Angualr1.5:

.compoment('counter',  {
bindings: {
count: '='
},
controller: function () {
function increment() {
this.count++;
}
function decrement() {
this.count--;
}
this.increment = increment;
this.decrement = decrement;
},
controllerAs: 'vm',
template: function($element, $attrs){
return [
'<div class="todo">',
'<input type="text" ng-model="vm.count">',
'<button type="button" ng-click="vm.decrement();">-</button>',
'<button type="button" ng-click="vm.increment();">+</button>',
'</div>'
].join('');
},
// restrict: 'E',
// transclude: true
});
  • Direcitve need pass in function, compoment need pass in object.
  • 'scope' and 'bindToController' can be replaced with just 'bindings'
  • by default restrict: 'E'
  • by default transclude: true
  • by default, if not given controllerAs, angular will create for you and name is the same as compoment name

[AngularJS] Exploring the Angular 1.5 .component() method的更多相关文章

  1. Exploring the Angular 1.5 .component() method

    Angular 1.5 introduced the .component() helper method, which is much simpler than the.directive() de ...

  2. [Angular] Use Angular components in AngularJS applications with Angular Elements

    When migrating AngularJS (v1.x) applications to Angular you have different options. Using Angular El ...

  3. AngularJs学习笔记--Understanding the Model Component

    原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular文档讨论的上下文中,术语“model”可以 ...

  4. AngularJs学习笔记--Understanding the Controller Component

    原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model 在angular中,controller是一个javasc ...

  5. 【js类库AngularJs】解决angular+springmvc的post提交问题

    [js类库AngularJs]解决angular+springmvc的post提交问题 AngularJS诞生于2009年,由Misko Hevery 等人创建,后为Google所收购.是一款优秀的前 ...

  6. [AngularJS] Using the Angular scope $destroy event and method

    With Angular scopes, you have access to a $destroy event that can be used to watch $scope events. Th ...

  7. [AngularJS] Test an Angular Component with $componentController

    Traditionally you had to create DOM elements to test a directive but by shifting our focus to compon ...

  8. [AngularJS] Lazy loading Angular modules with ocLazyLoad

    With the ocLazyLoad you can load AngularJS modules on demand. This is very handy for runtime loading ...

  9. [AngularJS] New in Angular 1.3 - Performance Boost with debugInfoEnabled

    By default, Angular provides a lot of debug information on the DOM that's only necessary for tools l ...

随机推荐

  1. 使用ul,添加新闻信息列表

    在浏览网页时,你会发现网页上有很多信息的列表,如新闻列表.图片列表,如下图所示. 新闻列表 图片列表 这些列表就可以使用ul-li标签来完成.ul-li是没有前后顺序的信息列表. 语法: <ul ...

  2. cocoapods安装失败

    ERROR:  While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the ...

  3. ASP.NET菜鸟之路之登录系统

    背景 我是一个ASP.NET菜鸟,暂时开始学习ASP.NET,在此记录下我个人敲的代码,没有多少参考价值,请看到的盆友们为我点个赞支持我一下,多谢了. 网站介绍 根据书上的例子做了一个比较粗糙的登录例 ...

  4. Log4Net使用指南(转)

    转自:http://www.cnblogs.com/dragon/archive/2005/03/24/124254.html 声明:本文内容主要译自Nauman Leghari的Using log4 ...

  5. Linux系统中,main函数的执行过程

    http://blog.csdn.net/rrerre/article/details/6728431

  6. jquery easy ui 学习 (7) TreeGrid Actions

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. insert 和 if x is not None

    insert(位置,元素) #!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc'] aList.insert( 3, 2009) print &qu ...

  8. Web Service相关工具的配置

    近期在学习Web Service Testing,使用到了soapUI这个工具,但是在学习之前,需要搭建Web Service环境,其中有关数据库的连接问题花费了我好多时间,主要还是自己对于很多配置不 ...

  9. ecilipse Javadoc文档注释

    — 标签 @param @param 空格后面跟上形参(不是数据类型)空格后跟着对该参数的描述. 在描述中第一个名字为该变量的数据类型 对于参数的描述是一个句子,最好不要首字母大写, 如果出现了句号这 ...

  10. 转:在虚拟机中用NAT方式连接网络

    1.安装VMware Workstation .在安装过VMware Workstation软件后,会在本地连接中,多了两个虚拟网卡,一个是 VMware Network Adapter for VM ...