使用具有降级角度的angularjs表达式绑定

时间:2017-07-07 13:00:32

标签: angular angularjs-directive angular-upgrade

假设我有一个复选框指令,我正在从angularjs

重写角度

checkbox.directive.js(angularjs)

template: `<some html> ...`,
scope: { checked: '=', onChecked: '&' }

checkbox.component.ts(angular)

@Component({
  selector: 'checkbox',
  templateUrl: '<some html> ...',
  ...
})
export class CheckboxComponent implements OnInit {
  @Input() checked: boolean;
  @Output() checkedChange = new EventEmitter<boolean>();
  @Output() onCheckedChange = new EventEmitter<boolean>();
  ...

如何从尚未升级的组件绑定到表达式绑定(&amp;)?

not-yet-upgraded.directive.js(angularjs)

template: '<checkbox (onChecked)="foo()"> ...',
controller: function($scope) { 
   $scope.foo = function() { console.log("change happened"); }   
}

1 个答案:

答案 0 :(得分:1)

事实证明,我有两个错误

  1. 事件输出不需要Change - 后缀,除非它是双向绑定
  2. angularjs消费者使用kebab-casing
  3. 所以:

    1。 angular component @Output()onChecked 更改 = new EventEmitter();

    2。 angularjs dom&lt; checkbox(on-checked)=“foo()”&gt; ...