2017-02-08 23 views
1

添加音樂後,我想在取消和節省主頁上的重定向按鈕點擊網頁..重定向到對角的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"); 
    }; 
    } 
]); 

主要部分去主頁上是這樣的:

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

它不重定向我在我的所有產品都列在主網頁..

+0

你對你的應用程序或鏈接小提琴? – Khaleel

+1

是@Khaleel https://plnkr.co/edit/tMAUSbCR4sXga9ilnmMe?p=preview請查看 – Dhara

+0

您在「view-detail.html」中看到錯誤。你忘了把雙引號放在'data-ng-model =「item.name」'和其他型號 – pryxen

回答

2

視圖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> 

你忘了把" "雙引號在data-ng-model=item.name應該data-ng-model="item.name"