可能是个愚蠢的问题……但我想做出最佳实践。所以..我有我的 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;
});
}
}
})();
现在我需要调用一个函数并使用
进行更改(是一个折叠列表) ng-click="toggleGroup(group)"
ng-class="{active: isGroupShown(group)}".
为此我需要使用 $scope 如何在我的 Controller 中集成 $scope?因为我最 Controller 是这样的:
.controller('MyCtrl', function($scope) {
...
});
感谢您的帮助!
最佳答案
你可以像注入(inject) $state 一样注入(inject) $scope,所以:
CanchaController.$inject = ['$state', '$scope', 'canchaService'];
function CanchaController($state, $scope, canchaService) { ...
关于javascript - 将 $scope 添加到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39908017/