Angular: Controller does not find Model

Asked

Viewed 67 times

0

On my main page shows me the error: Uncaught ReferenceError: Insidetv is not defined, i.e., the Controller is not finding the file of Model. But if I put the two in the same file works perfectly.

On the main page first is calling the Model and then the Controller and both pages are being found.

Model

var Insidetv = angular.module('Insidetv', []);

Insidetv.config(function($interpolateProvider){
    $interpolateProvider.startSymbol('[{');
    $interpolateProvider.endSymbol('}]');
});

Controller

Insidetv.controller('ListaController', function($scope, $http) {
    $scope.dragStop = function(e, ui) {
        console.log('ok');
    }

    $('.drop').sortable({
        connectWith: "ul",
        revert: true,
        appendTo: '.lista',
        helper: 'clone',
        stop: $scope.dragStop
    });
});
  • If you are putting the module in one file and the controller in another you need to set the controller inside a new module, because the two are loaded at the same time and the order doesn’t matter.

2 answers

2

2


As mentioned by Marcus Dacorrégio, it is not recommended to work this way.

The right thing to do would be to do something like this, each in its own separate file:

// app.module.js
angular.module('Insidetv', []);

// app.config.js
angular.module('Insidetv')
   .config(function($interpolateProvider){
      $interpolateProvider.startSymbol('[{');
      $interpolateProvider.endSymbol('}]');
   });

// lista.controller.js
angular.module('Insidetv')
   .controller('ListaController', function($scope, $http) {
      $scope.dragStop = function(e, ui) {
         console.log('ok');
      }

      $('.drop').sortable({
         connectWith: "ul",
         revert: true,
         appendTo: '.lista',
         helper: 'clone',
         stop: $scope.dragStop
      });
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.