让Angularjs ng视图工作

让Angularjs ng视图工作,angularjs,json,Angularjs,Json,我想知道如何用angularjs做一个水疗中心。我的路由正在工作,每个部分页面都在ng视图中正确加载。我正在尝试加载外部json数据。我让它在NCE上工作,但我不知道我做错了什么。目标是列出产品并为每个产品提供详细信息页面。任何帮助都将不胜感激。这是我的密码: app.js var myApp = angular.module('app', ['ngRoute']); myApp.config(['$routeProvider','$locationProvider', function(

我想知道如何用angularjs做一个水疗中心。我的路由正在工作,每个部分页面都在ng视图中正确加载。我正在尝试加载外部json数据。我让它在NCE上工作,但我不知道我做错了什么。目标是列出产品并为每个产品提供详细信息页面。任何帮助都将不胜感激。这是我的密码:

app.js

var myApp = angular.module('app', ['ngRoute']);
myApp.config(['$routeProvider','$locationProvider',    function($routeProvider,$locationProvider) {
        $routeProvider.
        when('/home',{
            templateUrl: 'partials/home.html',
            controller: "storeCtrl"
        }).
        when('/about',{
            templateUrl: 'partials/about.html',
            controller: "storeCtrl"
        }).
        when('/computers',{
            templateUrl: 'partials/computers.html',
            controller: "storeCtrl"
        }).
        when('/smartphones',{
            templateUrl: 'partials/smartphones.html',
            controller: "storeCtrl"
        }).
        when('/tablets',{
            templateUrl: 'partials/tablets.html',
            controller: "storeCtrl"
        }).
        otherwise({
            redirectTo: '/home'             
        });
    }]);

myApp.controller('storeCtrl', ['$scope', '$http', function($scope, $http) {


$scope.homeHeading = 'Home';
$scope.aboutHeading = 'About Us';
$scope.computersHeading = 'Computers';
$scope.smartphonesHeading = 'Smartphones';
$scope.tabletsHeading = 'Tablets';

$http.get('products.json').success(function(data) {
    $scope.products = data;

});
console.log($scope.products);

}]);
computers.html

<div ng-controller="storeCtrl">
<h1>{{computersHeading}}</h1>

<div ng-repeat="item in products">
<p>{{ item.name }}</p>
</div>

</div>

{{计算机阅读}
{{item.name}

您应该试试这个

$http.get('products.json').then(function(result) {
$scope.products = result.data;

});

并从视图中删除ng controller,因为您已经在myApp.config()中定义了它。

尝试使用返回承诺对象的
$http.get
服务。

您希望发生什么,以及会发生什么?请注意,您不应该有
ng controller=“storeCtrl”
:您已经定义了该部件在路由配置中应该有哪个控制器。您会遇到任何错误吗?我希望发生的是,json文件中的产品将使用ng repeat列出。当我尝试访问和项属性(例如{item.name})时,什么也没有发生。在视图中,我看到了花括号及其内容。@RahulArora我没有收到任何错误。我从每个部分页面中删除了ng控制器,并尝试了您的解决方案,我的部分仍然有效,但我的json数据没有输入。以下是该项目的链接:www.jewebdevlop.com/angularpracces您的链接不起作用。你能给我提供完整的代码吗?通过查看页面源代码,我看不到你的全部代码。你必须给我提供代码来知道发生了什么。你能给我提供你的json文件吗。您的Json文件中有错误。json文件或其名称的路径不正确。。它的Shoeeing错误404找不到。只需阅读您的评论,我就发现了错误,我将路径更改为js/products.json,并验证了我的json,它正常工作。非常感谢你的帮助。