什么是角度UI组件?任何人都可以告诉我

时间:2015-12-28 06:18:03

标签: angularjs

自定义指令和Ui组件之间是否有任何区别。请有人告诉我差异和用法。

1 个答案:

答案 0 :(得分:0)

component是应用程序' 可重用的UI构建块。它创建了自己的行为视图(DOM元素的新层次结构)。

@Component({selector: 'greet', template: 'Hello {{name}}!', directives:  [CustomDirective]})
class Greet {
  name: string = 'World';
}

可以用作html:

<greet></greet>


directive通过事件侦听器向现有元素(DOM)添加行为。

angular.module('simpleDirective', [])
  .controller('Controller', ['$scope', function($scope) {  }])
  .directive('myDirective', function() {
    return {
      template: ''
    };
  });

可以用作:

<div ng-controller="Controller">
  <div my-directive></div>
</div>