Skip to content

Instantly share code, notes, and snippets.

@dennis-8
Created August 13, 2018 12:31
Show Gist options
  • Save dennis-8/b3f70969e64a2fb2a70ca674ef93f3eb to your computer and use it in GitHub Desktop.
Save dennis-8/b3f70969e64a2fb2a70ca674ef93f3eb to your computer and use it in GitHub Desktop.
How to add ng-model functionality to AngularJS component
Link: https://stackoverflow.com/questions/44594532/how-to-add-ng-model-functionality-to-a-component/44595910#44595910
@dennis-8
Copy link
Author

app.component("checkboxComponent", {
    bindings: { ngModel: '<' },
    require: { ngModelCtrl: 'ngModel' },
    template: `
          <input type=checkbox ng-model='$ctrl.ngModel'
                 ng-change="$ctrl.ngModelChange()" />
    `,
    controller: function() {
      this.ngModelChange = () => {
        this.ngModelCtrl.$setViewValue(this.ngModel);
      };
    }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment