V
V
Vitaly Kirenkov2015-04-24 19:53:36
Angular
Vitaly Kirenkov, 2015-04-24 19:53:36

How to pass data from one template to another?

Hello.
For the first time I’m trying to write an application in Angular myself, and the question is probably simple, but I can’t enter where the dog is buried ((
There is a catalog, by clicking on an element you need to show its detailed page. The transition is done, but I don’t understand how to pull up the data.
There is still a router

angular.module("ShoppingCart", ["ngRoute"])
  .controller("catalogListController", function(){
    this.catalogItems = arrCatalog;
    this.catalogItemsCategories = arrCategories;
  })

  .config(function($routeProvider){
    $routeProvider
      .when("/", {
        templateUrl: "templates/catalog-index.html"
      })
      .when("/create", {
        templateUrl: "templates/create-index.html"
      })
      .when("/:id", {
        templateUrl: "templates/item-index.html"
      })
      .otherwise({
        redirectTo: "/"
      })
  })

There is a model
var arrCatalog = [
  {
    id: 0,
    title: "TV 1",
    description: "Some description for TV 1",
    price: "$ 13",
    image: "upload/tv-1.jpg",
    type: {tv: true}
  },
  {
    id: 1,
    title: "TV 2",
    description: "Some description for TV 2",
    price: "$ 23",
    image: "upload/tv-2.jpg",
    type: {tv: true}
  },

And this is how the link looks like
<a ng-href="#/{{catalogItem.id}}">
And here is the detailed template
<h1 class="page-header">{{title}}</h1>

<div class="row catalog-inner">
  <div class="col-xs-6">
    <div class="img-big"><img src="upload/notebook-1.jpg" alt=""></div>
  </div>
  <div class="col-xs-6">
    <div class="price">$ 20</div>
    <div class="description">description</div>
    <div class="quantity">
      <form action="#" class="form-inline clearfix">

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2015-04-24
@telray

For the page to which you go, a controller must be specified, in which you can get the desired element with data by id.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question