Angualr 1.4:

  1. .directive('counter', function counter() {
  2. return {
  3. scope: {},
       restrict: 'EA',
    transclude: true,
  4. bindToController: {
  5. count: '='
  6. },
  7. controller: function () {
  8. function increment() {
  9. this.count++;
  10. }
  11. function decrement() {
  12. this.count--;
  13. }
  14. this.increment = increment;
  15. this.decrement = decrement;
  16. },
  17. controllerAs: 'counter',
  18. template: [
  19. '<div class="todo">',
  20. '<input type="text" ng-model="counter.count">',
  21. '<button type="button" ng-click="counter.decrement();">-</button>',
  22. '<button type="button" ng-click="counter.increment();">+</button>',
  23. '</div>'
  24. ].join('')
  25. };
  26. });

Angualr1.5:

  1. .compoment('counter', {
  2. bindings: {
  3. count: '='
  4. },
  5. controller: function () {
  6. function increment() {
  7. this.count++;
  8. }
  9. function decrement() {
  10. this.count--;
  11. }
  12. this.increment = increment;
  13. this.decrement = decrement;
  14. },
  15. controllerAs: 'vm',
  16. template: function($element, $attrs){
  17. return [
  18. '<div class="todo">',
  19. '<input type="text" ng-model="vm.count">',
  20. '<button type="button" ng-click="vm.decrement();">-</button>',
  21. '<button type="button" ng-click="vm.increment();">+</button>',
  22. '</div>'
  23. ].join('');
  24. },
  25. // restrict: 'E',
  26. // transclude: true
  27. });
  • 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. 一、初识T4引擎

    对于代码生成器我们并不陌生,在日常编码中这也是用的比较多的工具之一.一般代码生成器主要功能是生成公共或基础代码来减少编码人员的工作量,而一款优秀的代码生成器除了生产代码以外,同时兼具生成项目架构和基础 ...

  2. NPM环境搭建

    1. NPM全局路径:配置npm包的安装位置,在你的用户文件夹下,新建.npmrc文件:cache=D:\NodeJs\nvm\npm-cache 表示缓存文件夹 prefix=D:\NodeJs\n ...

  3. 关于T-SQL重编译那点事,内联函数和表值函数在编译生成执行计划的区别

    本文出处:http://www.cnblogs.com/wy123/p/6266724.html 最近在学习 WITH RECOMPILE和OPTION(RECOMPILE)在重编译上的区别的时候,无 ...

  4. 30.SSH配置文件模板.md

    [toc] 1.struts2 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts ...

  5. 一种实现C++反射功能的想法(一)

    Java的反射机制很酷, 只需知道类的名字就能够加载调用. 这个功能很实用, 想象一下, 用户只需指定类的名称, 就可以动态绑定类型, 而且只需通过字符串指定, 字符串的使用可以使得用户的修改只需修改 ...

  6. Qt之QCustomPlot绘图(一)配置和第一个例子

    最近一个用Qt开发的项目需要绘制坐标曲线,我在老师的指点下使用了QCustomPlot这个插件,使用方法简单,功能还算不错. 可是在网上找了很多资料和博文都只是将官方提供的例子演示一遍,没有系统全面的 ...

  7. nuc900 nand flash mtd 驱动

    nuc900 nand flash mtd 驱动,请参考! /* * Copyright © 2009 Nuvoton technology corporation. * * Wan ZongShun ...

  8. javascript 中的nextSibling和previousSibling使用注意事项

    JavaScript中的nextSibling和previousSibling和作用类似于jquery的next()和prev(),都是获取下一个/上一个同胞元素,如果下一个同级节点不存在,则此属性返 ...

  9. Jquery中$.post()与$.get()区别

    1:GET访问 浏览器 认为 是等幂的 就是 一个相同的URL 只有一个结果[相同是指 整个URL字符串完全匹配] 所以 第二次访问的时候 如果 URL字符串没变化 浏览器是 直接拿出了第一次访问的结 ...

  10. CentOS 5.6服务器配置YUM安装Apache+php+Mysql+phpmyadmin

    1. 更新系统内核到最新. [root@linuxfei ~]#yum -y update 系统更新后,如果yum安装时提示错误信息,请执行以下命令修复. [root@linuxfei ~]#rpm ...