angular-fullstack / generator-angular-fullstack

Yeoman generator for an Angular app with an Express server
https://awk34.gitbook.io/generator-angular-fullstack
6.12k stars 1.24k forks source link

Support bind-to-controller syntax #1544

Open justusromijn opened 8 years ago

justusromijn commented 8 years ago

Currently, when I generate new routes or controllers, it will inject $scope by default. However, Angular supports (and is moving to) binding to controllers, so you won't be needing $scope anymore. Syntax is then for a route:

.when('/someRoute', {
        templateUrl: 'app/someRoute/someRoute.html',
        controller: 'someRouteCtrl',
        bindToController: true, // this needs to be added
        controllerAs:'someRoute' // this needs to be added
      });

And the controller:

'use strict';

angular.module('yourApp')
  .controller('someRouteCtrl', function () { // note: no $scope injection anymore
    var vm = this; // this needs to be added.

    vm.message = 'Hello'; // this is available in view
  });
Awk34 commented 8 years ago

Yeah, so we'ved moved all of the default views created by the generator to use controllerAs, etc, but the route subgenerator isn't a part of this generator. It's actually part of a different repository (generator-ng-component) that we include and call into from this generator. I know I still have to go and add an option to use newer syntax in the other generator (classes, controllerAs, etc), I just haven't gotten around to it.

justusromijn commented 8 years ago

Allright, I'll check if I have some time to set up a PR for it.

Op zondag 10 januari 2016 heeft Andrew Koroluk notifications@github.com het volgende geschreven:

Yeah, so we'ved moved all of the default views created by the generator to use controllerAs, etc, but the route subgenerator isn't a part of this generator. It's actually part of a different repository ( generator-ng-component https://github.com/DaftMonk/generator-ng-component) that we include and call into from this generator. I know I still have to go and add an option to use newer syntax in the other generator (classes, controllerAs, etc), I just haven't gotten around to it.

— Reply to this email directly or view it on GitHub https://github.com/angular-fullstack/generator-angular-fullstack/issues/1544#issuecomment-170387180 .