【问题标题】:How to make angular controller minification safe如何使角度控制器缩小安全
【发布时间】:2015-04-22 01:33:17
【问题描述】:

我正在将我的角度控制器更改为对缩小友好,但我的 $resource 调用出现错误。我所有的工厂看起来都和我发布的一样。我已经按照在线教程进行操作,但对我来说不起作用。

//'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);
        });
};//

工厂

'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);
    }
   };
 }]);

错误

ReferenceError: 类型未定义

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

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

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

【问题讨论】:

  • $scope.docTypes = Type.query(function () { });这是什么类型?您似乎没有在控制器的依赖项列表中提到这一点
  • 我想你回答了我的问题。我不确定是否需要包括它们。查看更新。
  • 您已经声明了一个名为“Type”的工厂。这需要在您的控制器依赖项中列出
  • 好的,把它放在答案中,这样我就可以给你信用了
  • 您需要包含您想要注入控制器的所有内容。成为服务、工厂、常量。

标签: angularjs


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-08-15
    • 2015-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多