将ng-repeat数据从一个页面发送到另一个页面 - 有角度

时间:2022-05-30 09:53:02

I have one table and i am iterating tr on click of button

我有一个表,我在点击按钮迭代tr

<table class="addedProject"  ng-show="show" width="100%" border="1" cellpadding="10"  >

        <tr ng-repeat="developerAdd in developer" ng-click="addDev(developerAdd);">
          <td >  <ion-item menu-close href="#/app/playlist" >{{ developerAdd.devname }}</ion-item> </td>
           <td><ion-item menu-close href="#/app/playlist" >{{ developerAdd.emailid }}</ion-item></td>
            <td><a  class="button button-small button-dark" ng-click="removeDev($index)">X</a></td>
          </tr>
        </table>

<button  class="button button-block button-positive"  ng-click="addDeveloper()">Add Developer</button>

This is page X

这是第X页

I want the all iterated tr to be in new page Y.

我希望所有迭代的tr都在新页面Y.

Here is my controller.

这是我的控制器。

.controller('fineAppCtrl',function($scope,$rootScope){

    console.log("fineAppCtrl");
    $scope.details = function(a){
        $rootScope.nameObj = a.name;
        $rootScope.ownerObj = a.title;

    };
     $scope.people = [];

    $scope.submitFlag = false;
    $scope.show = false;
    $scope.hidetable = false;

    $scope.create =function(){
    if($scope.show == false){
        $scope.show = true;

        }
        if($scope.submitFlag == false){
        $scope.submitFlag = true;

        }

    }
  $scope.addPerson = function(){
    $scope.hidetable = true;
    var person = {
        name: $scope.name,
        age: $scope.age,
        title: $scope.title,
    };
    $scope.people.push(person);
    if($scope.submitFlag == true){
        $scope.submitFlag = false;
        }
};
    $scope.removePerson = function(index){
    $scope.people.splice(index, 1);
    //console.log(index);
    var rows = document.getElementById('rowIteration')
    .getElementsByTagName('tbody')[0]
    .getElementsByTagName('tr').length;
        console.log(rows);
        if($scope.submitFlag == false && rows == 1){

        $scope.show = false;
        }
   };

   $scope.addDeveloper = function(){
    var developerAdd = {
      devname : $scope.devname,
      releasedate : $scope.releasedate,
      emailid: $scope.emailid,
      phonenumber : $scope.phonenumber,

       };
       $scope.developer.push(developerAdd);
        $scope.removeDev = function(index){
         $scope.developer.splice(index, 1);
   };
  };




})

I am very new in angular so my bad if code is not as per standard

我是一个非常新的角度,所以我的不好,如果代码不符合标准

1 个解决方案

#1


1  

Add developer to the $rootScope and pass that value to your local scope

将开发人员添加到$ rootScope并将该值传递给本地范围

$scope.addDeveloper = function () {
     ...
     $rootScope.developers.push(...);
     $scope.developers = $rootScope.developers;
 };

And on second page use this $rootScope to populate local $scope and add new ones to it, it will be also accessible to first one. Here is a little example on jsfiddle http://jsfiddle.net/ae8neq3k/

在第二页上使用此$ rootScope来填充本地$ scope并向其添加新的作用域,第一页也可以访问它。这是jsfiddle的一个小例子http://jsfiddle.net/ae8neq3k/

#1


1  

Add developer to the $rootScope and pass that value to your local scope

将开发人员添加到$ rootScope并将该值传递给本地范围

$scope.addDeveloper = function () {
     ...
     $rootScope.developers.push(...);
     $scope.developers = $rootScope.developers;
 };

And on second page use this $rootScope to populate local $scope and add new ones to it, it will be also accessible to first one. Here is a little example on jsfiddle http://jsfiddle.net/ae8neq3k/

在第二页上使用此$ rootScope来填充本地$ scope并向其添加新的作用域,第一页也可以访问它。这是jsfiddle的一个小例子http://jsfiddle.net/ae8neq3k/