托管AngularJS和图像的问题

时间:2014-04-25 18:50:47

标签: asp.net-mvc angularjs azure web-hosting

我想通过声明我对发展非常陌生来提出这个问题,所以请提前道歉。

基本上,我已经将我的网站部署到了Azure-在LocalHost上运行得很好,部署了除角度和图像之外的所有工作。

对于我的图片:

  

无法加载资源:服务器响应状态为404(未找到)windmillcontractors.azurewebsites.net/images/windmillFreshCut64.png

我的路径不正确,但我不确定我缺少什么来纠正它。我还想注意我的favicon没有显示,我认为这与windmillFreshCut64.png在同一文件夹中的原因相同。

对于Angular:

我收到错误导致我相信实例化,Angular无法找到依赖项。这是:

  

未捕捉错误:[$ injector:modulerr] http://errors.angularjs.org/1.2.16/ $ injector / modulerr?p0 = registrationModule ... angularjs.org%2F1.2.16%2F%24injector%2Funpr%3Fp0%3Dn%0A%20%20% 20%20at%20Er ...... 1)angular?v = Yj0JoRijZo-WbXksXxT7R8FZxhv6PQ59Vkm83GDIbm41:1

Angular Error DocumentationMore Documentation

这是我的注册模块:

var registrationModule = angular.module('registrationModule', ['ngRoute',       'ngResource'])
.config(function ($routeProvider) {
$routeProvider.when('/Estimates', { templateUrl: 'Scripts/templates/estimates.html',     controller: 'EstimatesCtrl' })
 .otherwise('/');
//.when('/Portal/Customers', { templateUrl: 'templates/customers.html', controller:    'CustomersCtrl' })
//$locationProvider.html5mode(true);
});

registrationModule.controller('EstimatesCtrl', function ($scope, $http, $rootScope) {

    $http.get("Portal/Estimates").success(function(data){ $scope.estimates =     data}).error(function(data){console.log(data)});



 $scope.viewEstimate = function (estimate) {
    $rootScope.estimate = estimate;
};


$scope.currentPage = 0;
$scope.pageSize = 20;

$scope.data = $http.get("Portal/Estimates").success(function (data) { $scope.estimates   = data }).error(function (data) { console.log(data) });

//$scope.estimateArray = jQuery.makeArray($scope.data);

//$scope.dataArray = Array.prototype.slice.call($scope.data);
//$scope.newArray = [];

//for (var key in $scope.data) {
//    $scope.newArray.push(key);
//};

//alert(jQuery.makeArray($scope.data));

//Object.keys($scope.data)
$scope.numberOfPages = Math.ceil($scope.data.length / $scope.pageSize);//not working

$scope.resetFilter = function () {
    $route.reload();
}


});

registrationModule.filter('isoToMS', function () {
return function (input) {
    var dateAsFromServerSide = input;

    var parsedDate = new Date(parseInt(dateAsFromServerSide.substring(6)));

    var jsDate = new Date(parsedDate); //Date object

    return jsDate;
};
});

registrationModule.filter('startFrom', function () {
return function (input, start) {
    start = +start; //parse to int
    return input.slice(start);
}
});

这是我的捆绑配置:

    bundles.Add(new ScriptBundle("~/bundles/angular").Include(
                 "~/Scripts/angular.js",
                 "~/Scripts/angular-resource.js",
                 "~/Scripts/angular-route.js",
                 "~/Scripts/Registration-Module/registration-module.js"
               ));

由于

2 个答案:

答案 0 :(得分:3)

因为你已经捆绑了javascript并且它正在缩小你的脚本,所以服务名称将被破坏,你需要在声明你的控制器时使用以下模式

    registrationModule.controller('EstimatesCtrl', ['$scope', '$http', '$rootscope', function ($scope, $http, $rootScope) {
       $http.get("Portal/Estimates")
          .success(function(data){
             $scope.estimates = data
           })
          .error(function(data){console.log(data)});
       $scope.viewEstimate = function (estimate) {
       $rootScope.estimate = estimate;
    };
  }]);

这将允许angular通过适当的字符串名称注入依赖项,这些名称将在最小化期间​​保留。

答案 1 :(得分:1)

您的角度误差是因为您没有正确设置控制器以进行缩小。

registrationModule.controller('EstimatesCtrl',[ // notice the array brackets
    '$scope', '$http', '$rootScope', // annotated with injected dependencies
    function ($scope, $http, $rootScope) {
    // etc.
    }
  ] // be sure to close the array
);

当你缩小角度时,不知道要注射什么。这是你的控制器在缩小时所处的位置:

registrationModule.controller("EstimatesCtrl", function(n, t, i) {
    t.get("Portal/Estimates").success(function(t) {
        n.estimates = t
    }).error(function(n) {
        console.log(n)
    });
    n.viewEstimate = function(n) {
        i.estimate = n
    };
    n.currentPage = 0;
    n.pageSize = 20;
    n.data = t.get("Portal/Estimates").success(function(t) {
        n.estimates = t
    }).error(function(n) {
        console.log(n)
    });
    n.numberOfPages = Math.ceil(n.data.length / n.pageSize);
    n.resetFilter = function() {
        $route.reload()
    }
});

AngularJS决定注入函数的方式是通过获取函数并调用toString(),然后解析出参数的名称。它在这里失败了,因为您没有名为nti的服务。

通过使用注入注释的依赖项数组调用它,它将成为:

registrationModule.controller("EstimatesCtrl", ['$scope', '$http', '$rootScope', function(n, t, i) {
    // etc
}]);

现在,n == $scopet == $http$rootScope == i。由于缩小代码并不会破坏字符串,因此AngularJS知道注册服务需要注入的内容。

编辑:我忘了提..这需要在有依赖注入的任何地方进行。查看dependency injection documentation了解详情。

相关问题