0

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

checkbox.directive.js (angularjs)

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

checkbox.component.ts(角度)

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

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

尚未升级的.directive.js (angularjs)

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

1 回答 1

2

事实证明,我犯了两个错误

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

所以:

1. angular component@Output() onChecked Change = new EventEmitter();

2. angularjs dom<checkbox (on-checked)="foo()"> ...

于 2017-07-07T13:18:52.737 回答