未捕获错误:未知提供者:来自productsApp的$ controllerProvider

时间:2015-12-14 09:23:17

标签: html angularjs json xml

这是我的代码链接

http://plnkr.co/edit/8muxhJmvFiIqRJgzuT0O?p=preview

我收到错误 未捕获错误:未知提供者:来自productsApp的$ controllerProvider

我无法在控制台中查看json文件

的index.html

<!DOCTYPE html>
<html data-ng-app="productsApp" >
<head>
  <meta charset="utf-8">
  <script data-require="angularjs@1.3.6" data-semver="1.3.6" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.js"></script>
                    <script type="text/javascript" src="http://demos.amitavroy.com/learningci/assets/js/xml2json.js" charset="UTF-8"></script>

  <script>document.write('<base href="' + document.location + '" />');</script>
 <script  type='text/javascript' src="script.js"></script> 
  <script data-require="angular.js@1.0.x" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js" data-semver="1.0.8"></script>
</head>

  <body >
<div ng-controller="products">
    <div ng-repeat="product in products">
        <div ng-repeat="platform in product ">
        {{platform._type}}
        </div>
    </div>
</div>
</body>
</html>

product_js.js - x2js的js文件

var productApp = angular.module("productsApp",[]);
productApp.factory('productFactory',function($http){
    var factory = [];
    factory.getProducts = function(){
        return $http.get("operations_mapping.xml");
    }
    return factory;
});
productApp.controller('products',function($scope,productFactory){
    $scope.products = [];
    loadProducts();
    function loadProducts(){
        productFactory.getProducts().success(function(data){
            mappingss = x2js.xml_str2json(data);
            console.log(mappingss.mappings.platform);
            $scope.products =mappingss.mappings.platform;
        });
    }
});

2 个答案:

答案 0 :(得分:0)

product_js.js未包含在您的HTML中。添加<script type='text/javascript' src="product_js.js"></script>

答案 1 :(得分:0)

看起来您已在页面上包含多个版本的angular.js脚本,保留最新版本(如下所述)并删除其余参考文件。

<script data-require="angularjs@1.3.14" data-semver="1.3.14" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">

Here is the Updated Plunker