0

我想创建一个简单的角度电子商务,但我有一个大问题。如何创建列表视图,当我单击一个项目时,使用 $params 和数据服务转到详细视图?

服务

app.service("productService", function (filterFilter, $http, $routeParams) {

var items = [];

var promise = $http.get('process/product-view.php').then(function (res){

    return items = res.data;

});

this.getProducts = function (){

    return promise;

};


this.getProductAt = function(_name) {


    return promise.then(function (res){

        console.log(JSON.stringify(items));

        return filterFilter(items, {

            link_page: _name

        })[0];
    });
};
});

控制器

店铺

app.controller('shop', ['$scope', '$http', 'productService', function ($scope, $http, productService){

productService.getProducts().then(function (res){
    $scope.products = res;
    // console.log(JSON.stringify(res));
});
}]);

单项

app.controller('single-item', ['$scope', '$routeParams', 'productService', function ($scope, $routeParams, productService){
    $scope.product = productService.getProductAt($routeParams.item);

}]);

谢谢 !

4

0 回答 0