0
angular.module('CrudApp', []).
config(['$routeProvider', function($routeProvider) {
  $routeProvider.
  when('/', {
    templateUrl: 'assets/tpl/lists.html',
    controller: ListCtrl
  }).
  when('/add-user', {
    templateUrl: 'assets/tpl/add-new.html',
    controller: AddCtrl
  }).
  otherwise({
    redirectTo: '/'
  });
}]);

function ListCtrl($scope, $http) {
  $http.get('api/users').success(function(data) {
    $scope.users = data;
  });
}

function AddCtrl($scope, $http, $location) {
  $scope.master = {};
  $scope.activePath = null;

  $scope.add_new = function(user, AddNewForm) {
    console.log(user);

    $http.post('api/add_user', user).success(function() {
      $scope.reset();
      $scope.activePath = $location.path('/');
    });

    $scope.deleteCustomer = function(customer) {
      $location.path('/');
      if (confirm("Are you sure to delete customer number: " + $scope.fld_Customer_Key) == true)
        services.deleteCustomer(customer.customerNumber);
    };

    $scope.reset = function() {
      $scope.user = angular.copy($scope.master);
    };

    $scope.reset();

  };
}
// Delete user

I keep getting the error scope not defined and cannot seem to figure out why. can anybody help me troubleshoot this? All of the other functions are working except the delete customer. I don't know what is causing the error

Joseph
  • 117,725
  • 30
  • 181
  • 234
  • 2
    Is it supposed to be intentional that `deleteCustomer` and `reset` are inside `add_new`? – Joseph Nov 05 '15 at 21:30
  • can you provide screenshot browser console with error? – Grundy Nov 05 '15 at 21:32
  • Looks like you are using too old angular version..Kindly upgrade it..because the syntax you are using are deprecated already.. Read up on this http://stackoverflow.com/a/28728380/2435473 ..About the error you might have use `Scope` somewhere instead of `$scope` – Pankaj Parkar Nov 05 '15 at 21:32
  • are you sure that _not defined_ really _scope_ and not _services_? I not where you get this variable: _services_ – Grundy Nov 05 '15 at 21:35
  • @MaddisonGruinn have you tried my solution? – Rodmentou Nov 07 '15 at 18:51

1 Answers1

0

Working Plunker

Here is it. I've updated your sintax, installed the dependencies and your $scope is working. Look at the Plunker. :)

Markup:

  <body ng-app="CrudApp">
    <div ng-controller="ListCtrl">
      List Controller says what? {{what}}
    </div>
    <div ng-controller="AddCtrl">
      Add Cntroller says What? {{what}}
    </div>
  </body>

script.js

var app = angular.module('CrudApp', ['ngRoute']);

app.controller('ListCtrl', function ($scope, $http) {
  $scope.what = 'Rodrigo souza is beauty';
  $http.get('api/users').success(function(data) {
    $scope.users = data;
  });

});


app.controller('AddCtrl', function ($scope, $http, $location) {
  $scope.what = 'Rodrigo souza looks like Shrek';
  $scope.master = {};
  $scope.activePath = null;

  $scope.add_new = function(user, AddNewForm) {
    console.log(user);

    $http.post('api/add_user', user).success(function() {
      $scope.reset();
      $scope.activePath = $location.path('/');
    });

    $scope.deleteCustomer = function(customer) {
      $location.path('/');
      if (confirm("Are you sure to delete customer number: " + $scope.fld_Customer_Key) == true)
        services.deleteCustomer(customer.customerNumber);
    };

    $scope.reset = function() {
      $scope.user = angular.copy($scope.master);
    };

    $scope.reset();

  };

});

Working Plunker

Rodmentou
  • 1,610
  • 3
  • 21
  • 39