2017-02-08 7 views
1

Nach Hinzufügen von Musik ich auf Abbrechen und speichern auf der Hauptseite umleiten möchten ..Redirect auf Seite auf die Schaltfläche klicken in Winkel js

var app = angular.module("musicApp", ["ngRoute"]); 
app.config(function($routeProvider) { 
    $routeProvider.when("/Items", { 
     templateUrl: "view-list.html", 
     controller: "listController" 
    }) 
    .when("/Items/add", { 
     templateUrl: "view-detail.html", 
     controller: "addController" 
    }) 
    .when("/Items/:index", { 
     templateUrl: "view-detail.html", 
     controller: "editController" 
    }) 
    .otherwise({ 
     redirectTo: "/Items" 
    }); 
}); 


app.factory("productService", ["$rootScope", function($rootScope){ 
    var service={}; 
    var data = [{ 
     name: "Artist1", 
     genre: "Genre1", 
     rating: "Rating1" 
    }, { 
     name: "Artist2", 
     genre: "Genre2", 
     rating: "Rating2" 
    }]; 

    service.getProducts = function(){}; 
    service.addProduct = function(product){}; 
    service.editProduct = function(product){}; 
    return service; 
}]); 
app.controller("listController", ["$scope", "$location", "$routeParams", 
    function($scope, $location, $routeParams) { 

    $scope 

    $scope.addProduct = function() { 
     $location.path("/Items/add"); 
    }; 

    $scope.editItem = function(index) { 
     $location.path("/Items/" + index); 
    }; 

    } 
]); 

app.controller("addController", ["$scope", "$location", "$routeParams", 
    function($scope, $location, $routeParams) { 
    $scope.save = function() { 
     $location.url("/Items"); 
    }; 
    $scope.cancel = function() { 
     $location.path("/Items"); 
    }; 
    } 
]); 


app.controller("editController", ["$scope", "$location", "$routeParams", 
    function($scope, $location, $routeParams) { 
    $scope.save = function() { 
     $location.path("/Items"); 
    }; 
    $scope.cancel = function() { 
     $location.path("/Items"); 
    }; 
    } 
]); 

Hauptteil auf der Hauptseite zu gehen ist wie:

app.controller("addController", ["$scope", "$location", "$routeParams", 
    function($scope, $location, $routeParams) { 
    $scope.save = function() { 
     $location.url("/Items"); 
    }; 
    $scope.cancel = function() { 
     $location.path("/Items"); 
    }; 
    } 
]); 

Es macht mich nicht auf die Hauptseite umgeleitet, wo alle meine Produkte aufgeführt sind ..

+0

Haben Sie eine Geige für Ihre Anwendung oder Link haben? – Khaleel

+1

ja @Khaleel https://plnrkr.co/edit/tMAUSbCR4sXga9ilnmMe?p=preview bitte überprüfen Sie diese – Dhara

+0

Sie haben einen Fehler in Ihrem "View-Detail.html". Sie haben vergessen, doppelte Anführungszeichen in 'data-ng-model =" item.name "' und andere Modell – pryxen

Antwort

2

view-detail.html

<div class="form-group"> 
    <label for="txtName">Product Name</label> 
    <input type="text" id="txtName" class="form-control" data-ng-model="item.name" /> 
</div> 

<div class="form-group"> 
    <label for="cboGenre">Genre</label> 
    <input type="text" id="cboGenre" class="form-control" data-ng-model="item.genre"/> 
</div> 

<div class="form-group"> 
    <label for="cboRating">Rating</label> 
    <input type="text" id="cboRating" class="form-control" data-ng-model="item.rating"/> 
</div> 

<div class="form-group"> 
    <button class="btn bth-primary" data-ng-click="save()">Save</button> 
    <button data-ng-click="cancel()" class="btn bth-primary">Cancel</button> 
</div> 

Sie haben vergessen " " doppelte Anführungszeichen in Ihrem data-ng-model=item.name es sollte data-ng-model="item.name" setzen

Verwandte Themen