Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

javascript - Controller data set another page in angular

After that clicked user.html list. I have to show clicked product data in productDetail.html file.

ProductController.js

 $scope.selectedProduct = function(product)


{
    console.log(product.post_title);

  }

user.html

<div ng-repeat="p in users.products | filter:searchBox">

    <a href="#/{{$index}}/{{$index}}" ng-mouseover="selectedProduct(p)" ng-click="selectedProduct(p)" style="text-decoration:none;">
    <ion-item    class="item widget uib_w_109 d-margins item-button-left" data-uib="ionic/list_item_button" data-ver="0">
    {{p.post_title}} <br>

    </ion-item>
    </a>
    </div>

productDetail.html

<div class="users">

    <a>
    <ion-item   data-uib="ionic/list_item_button" data-ver="0">Product Name : {{clickedProduct.post_title}} <br>
        Product Id : {{selected.product}}<br>
        Post Date :  {{product.post_title}}


    </ion-item>
    </a>
    </div>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Need more Clarification, whether both HTML are shown in same view or different on product click.

here is a Plunker i made understanding your question and comments. https://plnkr.co/edit/Ii52KZkjpNndmAMvQQYU?p=preview

  $scope.products = [{
    ID: 'P1',
    post_title: 'product 1',
    post_date: '20th July 2016',
    post_author: 'John Doe'
  }, {
    ID: 'P2',
    post_title: 'product 2',
    post_date: '29th July 2016',
    post_author: 'Jane Doe'
  }, {
    ID: 'P3',
    post_title: 'product 3',
    post_date: '12th July 2016',
    post_author: 'John William'
  }];
  $scope.selectedProduct = {};
  $scope.selectProduct = function(index){
    $scope.selectedProduct = $scope.products[index];
  };

and here is the HTML

 <div>
    Product List
    <div ng-repeat="product in products">
        <ion-item>
          {{product.post_title}}
          <button ng-click="selectProduct($index)">select</button>
          <br>
        </ion-item>
    </div>
  </div>
  <div ng-include="'product.html'"></div>

the other HTML will pick the same angular controller.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...