如何使角度控制器缩小安全

时间:2021-07-11 16:01:39

I'm changing my angular controllers to minification friendly but I am getting a error with my $resource calls. all of my factories look the same as the one i am posting. I have followed the tutorials online but it is not working out for me.

我正在将我的角度控制器更改为简化友好,但我的$资源调用出错。我的所有工厂看起来和我发布的工厂一样。我已经在线学习了这些教程,但这对我来说并不奏效。

//'use strict';
  app.controller('documentCtrl', ['$scope', '$upload', '$filter', '$route',  '$sessionStorage','$sce', '$q', '$modal', '$http', '$location', '$rootScope',  function (
$scope, $upload, $filter, $route, $sessionStorage, $sce, $q, $modal, $http, $location, $rootScope) {


$scope.docTypes = Type.query(function () { });
$scope.selectType = function () {

    var id = $scope.typeId.TypeId
    $http.get('/api/apiType/' + id)
        .success(function (result) {
            $scope.TypeName = result.TypeName
            console.log($scope.TypeName);
        });
};//


$scope.docPipes = Pipe.query(function () { });

$scope.selectPipe = function () {
    var id = $scope.pipeId.PipeId
    $http.get('/api/apiPipe/' + id)
        .success(function (result) {
            $scope.PipeName = result.PipeName
            console.log($scope.PipeName);
        });
};//

Factory

'use strict'
 app.factory('Type',['$resource', function ($resource) {
return $resource('/api/apiType/:id', { id: '@_id' }, {
    get: {
        method: 'GET', isArray: false // this method issues a PUT request
    }
}, {
    stripTrailingSlashes: false
 });
}]);
  app.factory('TypeUpdate',['$http', function ($http) {
  return {

    update: function (doc) {
        return $http.put('/api/apiType/' + doc.TypeId, doc);
    }
   };
 }]);

Error

ReferenceError: Type is not defined

ReferenceError:未定义类型

Update Type is a $resource call defined in my factory.

更新类型是我工厂中定义的$资源调用。

Is this the way the controllers should be defined? The examples I found online did not include variables.

这是控制器的定义方式吗?我在网上找到的例子没有包含变量。

app.controller('documentCtrl', ['$scope', '$upload', '$filter', '$route', '$sessionStorage','$sce', '$q', '$modal', '$http', '$location', '$rootScope', 'ngTableParams', 'notificationFactory', 'Type', 'Document', 'Plant', 'Pipe', 'Company',  'Location', function (
$scope, $upload, $filter, $route, $sessionStorage, $sce, $q, $modal, $http, $location, $rootScope, ngTableParams, notificationFactory, Type, Document, Plant, Pipe, Company, Location) {

1 个解决方案

#1


2  

You have declared a factory called "Type". This needs to be listed in your controller dependencies.

您已声明一个名为“Type”的工厂。这需要在您的控制器依赖项中列出。

#1


2  

You have declared a factory called "Type". This needs to be listed in your controller dependencies.

您已声明一个名为“Type”的工厂。这需要在您的控制器依赖项中列出。