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");
};
}
]);
Это не перенаправляет меня на главную страницу, где все мои продукты перечислены ..
у вас есть скрипку для вашего приложения или ссылки? – Khaleel
yes @Khaleel https://plnkr.co/edit/tMAUSbCR4sXga9ilnmMe?p=preview, пожалуйста, проверьте это – Dhara
, у вас есть ошибка в вашем «view-detail.html». Вы забыли поместить двойные кавычки в 'data-ng-model =" item.name "и другую модель – pryxen