davej / angular-classy

Cleaner class-based controllers with Angular 1
http://davej.github.io/angular-classy/
813 stars 27 forks source link

Properties added through data are assigned to this and this.$ #39

Closed MikaAK closed 9 years ago

MikaAK commented 9 years ago

Recently I noticed that data that has been assigned via the data: {} property will not only get put on this.$ but also on this. Assigning properties via this.$.myProp = { a: 1, b: 2} only inserts them on scope and doesn't put them onto the this object of the controller.

davej commented 9 years ago

Yes, this is for zero-config compatibility with both $scope-style controllers and controllerAs (#4) controllers.

You can turn off binding to the $scope (this.$) by setting the addToScope option to false.

myApp.classy.options.controller = {
    bindData: {
        addToScope: false
    }
}

You can't currently prevent binding to this but I think that's a reasonable feature request so I will add it to Classy sometime this week.

davej commented 9 years ago

This is now fixed in master.

Example Usage:

angular.module('app').classy.options.controller = {
    bindData: {
        addToClass: false
    }
}