未定义范围

Scope not defined

本文关键字:范围 未定义      更新时间:2023-09-26
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

我一直没有得到未定义的错误范围,似乎无法弄清楚原因。 有人可以帮我解决这个问题吗?除删除客户外,所有其他功能都正常工作。我不知道是什么导致了错误

Working Plunker

就是这样。我已经更新了您的 sintax,安装了依赖项,您的$scope正在工作。看看普伦克。:)

标记:

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

脚本.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();
  };
});

工作普伦克