Is it possible to remove data from the different json-files into the angular rubber?



  • On a page from the angular, a page on which a carousel with an essential product is opened when the goods are transferred.

    I don't get the single json.

    Is it possible for ng-repeat to remove goods from different json files depending on the identifier? Or maybe there's a more simple solution?

    CONTROLLER

    [velesApp.controller('KitchenDetailCtrl',
        ['$scope','$http', '$location', '$routeParams', 
            function($scope, $http, $location, $routeParams) {
                $scope.kitchenId = $routeParams.kitchenId;
                var url = 'kitchens/'+$routeParams.kitchenId+'.json';
                $http.get(url).success(function(data) { 
                    $scope.kitchendet = data; 
                });
    

    HTML

    <slick ng-repeat="kitchendet in kitchendets ">
    <h2 class="text-center"> {{kitchendet.name}}
    

    MARCHITIZATION

    .when('/kitchens/:kitchenId', 
    { 
        templateUrl:'template/kitchen-detail.html', 
        controller:'KitchenDetailCtrl' 
    })
    


  • It's not the right approach to implementation, you need to use the service, not the best implementation, but as an example, my service will be fine, and I'm actually doing ngresource now. The Controller will only check if ID is here if there is one recording from Projects.items if there is no data in the items we try to download them from the server. I've got a post here because I'm still transmitting the parameters for the cutting of the images, in your case, you're gonna get enough.

    questServices.factory('Projects', ['$http', '$timeout', 'Upload',
        function ($http, $timeout, Upload) {
            var service = function (editor) {
                this.items = [];
                this.busy = false;
                this.after = '';
                this.page = '';
                this.end = false;
                this.new_project = {};
                this.getClass = 'btn-default';
                this.setdelete = null;
            };
    
        service.prototype.save = function () {
            if (this.busy)
                return;
            this.busy = true;
    
            var file = this.new_project.image;
            file.upload = Upload.upload({
                url: '/resource/addproject',
                data: {file: file, project: JSON.stringify(this.new_project)},
            });
    
            file.upload.then(function (response) {
                this.busy = false;
                console.log(response.data);
                this.new_project = {};
                this.getClass = 'btn-success';
                this.load();
                $timeout(function () {
                    this.getClass = 'btn-default';
                    this.busy = false;
                }.bind(this), 2000);
    
    
            }.bind(this), function (response) {
                //this.busy = false;
                //console.log('test');
                //console.log(response.data);
            }, function (evt) {
                // Math.min is to fix IE which reports 200% sometimes
                file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
                console.log(file.progress);
            });
    
    
        }
    
    
        service.prototype.load = function (params, callback) {
            if (this.busy)
                return;
            this.busy = true;
            var url = "resource/projects";
    
    
            $http.post(url, params).
            then(function (response) {
                console.log(response.data);
                this.items = response.data.projects;
                this.busy = false;
                $timeout(function () {
                    if (typeof callback == 'function')
                        callback();
                }.bind(this), 1000);
    
            }.bind(this), function (response) {
                console.log(response);
            });
    
    
        };
    
        service.prototype.delete = function () {
            if (this.busy)
                return;
            this.busy = true;
            var url = "resource/deleteproject/" + this.setdelete.id;
            $http.get(url).
            success(function (data, status, headers, config) {
                console.log(data);
    
                angular.forEach(this.items, function (item, key) {
                    if (item.id == this.setdelete.id) {
                        this.items.splice(key, 1);
                    }
                }.bind(this));
    
    
                this.setdelete = null;
    
    
                this.busy = false;
            }.bind(this)).
            error(function (data, status, headers, config) {
            });
        };
    
    
        service.prototype.update = function () {
            if (this.busy)
                return;
            this.busy = true;
            var url = "resource/updateproject";
    
    
            var file = this.new_project.image;
            if (file) {
                console.log('Отправил через файл');
                file.upload = Upload.upload({
                    url: url,
                    data: {file: file, project: JSON.stringify(this.new_project)},
                });
    
                file.upload.then(function (response) {
                    this.busy = false;
                    console.log(response.data);
    
                    this.getClass = 'btn-success';
                    this.load();
                    $timeout(function () {
                        this.getClass = 'btn-default';
                        this.new_project = {};
                        this.busy = false;
                    }.bind(this), 2000);
    
    
                }.bind(this), function (response) {
                    //this.busy = false;
                    //console.log('test');
                    //console.log(response.data);
                }, function (evt) {
                    // Math.min is to fix IE which reports 200% sometimes
                    file.progress = Math.min(100, parseInt(100.0 * evt.loaded / evt.total));
                    console.log(file.progress);
                });
            } else {
                $http.post(url, {project: JSON.stringify(this.new_project)}).
                then(function (response) {
                    console.log(response);
                    this.getClass = 'btn-success';
                    $timeout(function () {
                        this.getClass = 'btn-default';
                        this.busy = false;
                    }.bind(this), 2000);
                }.bind(this), function (response) {
                    console.log(response);
                });
            }
    
    
        };
    
    
        return service;
    }
    

    ]);


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2