Ionic项目

时间:2016-10-06 21:55:42

标签: javascript angularjs ionic-framework scope

我有一个错误:

  

angular.js:13424 ReferenceError:$ scope未定义

我知道我从未定义过$ scope。但是在这个脚本中,结构与我的代码不同(我试图用我的结构在我的控制器中实现这个脚本):

angular.module('ionicApp', ['ionic'])

.controller('MyCtrl', function($scope) {
$scope.groups = [];
for (var i=0; i<10; i++) {
  $scope.groups[i] = {
    name: i,
    items: ['example 1', 'example 2', 'example 3'],
    show: false
  };

}

/*
 * if given group is the selected group, deselect it
 * else, select the given group
 */
$scope.toggleGroup = function(group) {
  group.show = !group.show;
};
$scope.isGroupShown = function(group) {
  return group.show;
};

});

这是我的代码:

(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;

             for (var i=0; i<vm.canchasComplejo.length; i++) {
                vm.canchasComplejo[i] = {
                  name: i,
                  items: ['Informacion, Habilitado, Agenda'],
                  show: false
                };

              }

        });
    }

     $scope.toggleGroup = function(group) {
            group.show = !group.show;
        };

    $scope.isGroupShown = function(group) {
            return group.show;
        };   

}
})();

我改变了

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

要:

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

并且

function CanchaController($state, canchaService) {

要:

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

但仍然没有工作。

你能知道如何用我的结构正确实现脚本吗?

0 个答案:

没有答案