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

时间:2015-06-14 06:03:30

标签: javascript angularjs

我有一张桌子,我点击按钮

重复 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>

这是第X页

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

这是我的控制器。

.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);
   };
  };




})

我在角度方面非常新,所以如果代码不符合标准,那我就不好

1 个答案:

答案 0 :(得分:1)

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

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

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

的一个小例子