Federick Jons Federick Jons - 2 months ago 18
AngularJS Question

Add $scope to controller

May be is a stupid question... but I wanna make best practices. So.. I have my controller:

(function() {
'use strict';

angular
.module('example.cancha')
.controller('CanchaController', CanchaController);

CanchaController.$inject = ['$state', 'canchaService'];

function CanchaController($state, canchaService) {
var vm = angular.extend(this, {
canchasComplejo: []
});



(function activate() {
cargarCanchasComplejo();
})();

//funcion que llama al servicio para obtener las canchas del complejo
function cargarCanchasComplejo() {
canchaService.obtenerCanchasComplejo()
.then(function(canchasComplejo) {
vm.canchasComplejo = canchasComplejo;
});
}
}
})();


Now I need to call a function and make changes (is a collapse list) with

ng-click="toggleGroup(group)"

ng-class="{active: isGroupShown(group)}".


For this I need to use $scope
How can I integrate in my controller the $scope? Because I the most controller are like:

.controller('MyCtrl', function($scope) {
...
});


Thanks for helping!

Answer

you can inject $scope in the same way you are inject $state so:

CanchaController.$inject = ['$state', '$scope', 'canchaService'];

function CanchaController($state, $scope, canchaService) { ...