1

After adding music I want to redirect on main page on cancel and save..

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");
    };
  }
]);

Main portion to go on main page is like:

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

It does not redirect me to the main page where all my products are listed..

8
  • do you have a fiddle for your application or link? Commented Feb 8, 2017 at 6:37
  • 1
    yes @Khaleel plnkr.co/edit/tMAUSbCR4sXga9ilnmMe?p=preview please check this out Commented Feb 8, 2017 at 6:37
  • you got an error in your "view-detail.html". You forgot to put double quotes in data-ng-model="item.name" and other model Commented Feb 8, 2017 at 6:41
  • can you tell me which error @pryxen.. I couldn't find out Commented Feb 8, 2017 at 6:42
  • oh god thanks a lot @pryxen Commented Feb 8, 2017 at 6:45

1 Answer 1

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>

You forgot to put " " double quotes in your data-ng-model=item.name it should be data-ng-model="item.name"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.