Angularjs 如何根据所选内容重写ng重复数据

Angularjs 如何根据所选内容重写ng重复数据,angularjs,ng-repeat,Angularjs,Ng Repeat,var myfriend=angular.module('myfriend',[]); myfriend.controller('myfriendController',函数($scope) { $scope.record=[ {“id”:“01”, “名字”:“默翰”, “中间名”:“K”, “姓氏”:“Futterkiste1” },{ “id”:“04”, “名字”:“罗汉”, “中间名”:“A”, “姓氏”:“Futterkiste2” },{ “id”:“08”, “名字”:“苏汉”,

var myfriend=angular.module('myfriend',[]);
myfriend.controller('myfriendController',函数($scope)
{
$scope.record=[
{“id”:“01”,
“名字”:“默翰”,
“中间名”:“K”,
“姓氏”:“Futterkiste1”
},{
“id”:“04”,
“名字”:“罗汉”,
“中间名”:“A”,
“姓氏”:“Futterkiste2”
},{
“id”:“08”,
“名字”:“苏汉”,
“中间名”:“M”,
“姓氏”:“Futterkiste3”
}
]
$scope.myemp=函数(x)
{
//在这里罢工
//setItem('empid',x);
//$location.path('/myView');
//$rootScope.mydetails=true;
//$rootScope.addnewemp=false;
}
});
myfriend.controller('myprofileController',函数($scope)
{
$scope.myprofile=[
{“id”:“01”,
“名字”:“克里斯坦”,
“middlename”:“Micheal”,
“姓氏”:“D'souza”
}
]
});

我的初始配置文件:
身份证件
名字
中名
姓
{{x.id}
{{x.firstname}
{{x.middlename}}
{{x.lastname}


身份证件 名字 中名 姓 {{x.id} {{x.firstname} {{x.middlename}} {{x.lastname}
当您在
myfriendController

<th ng-click="selectInfo(x)">
  selectInfo(friend)={
    this.selectedFriend=friend;
  }
如果你在myprofile中推送新数据,它也会保留你的旧数据。所以不要推,只分配


注意:如果我误解了您的问题,请纠正我。

我已经为您准备了一个工作包:

一般的想法是使用服务在控制器之间共享数据

app.service('SelectedFriend', function() {
  var SelectedFriend = {
    friend: {
      "id" : "01",
      "firstname" : "Mohan ",
      "middlename" : "K",
      "lastname" : "Futterkiste1"
    } // default value
  };

  return {
    setFriend: function(friend) {
      SelectedFriend.friend = friend;
      console.log(SelectedFriend.friend);
    },
    getFriend: function() {
      return SelectedFriend.friend;
    }
  }
});
然后在控制器中使用它:

app.controller('myFriendController', function($scope, SelectedFriend) {
   // ...

   $scope.selectInfo = function(friend) {
     SelectedFriend.setFriend(friend);
   }
});

app.controller('myProfileController', function($scope, SelectedFriend) {
    $scope.myprofile = SelectedFriend;
});

请列出您的控制器并查看代码,以便人们可以帮助您提供一段代码,以便更好地了解您的问题并提供准确的解决方案。好的,我会在@Slava.KUpdate the code@Slava.KUpdate the code@ani5hait可能是错的。相反,正确的方法是通过服务传递密钥。我在上面的最后一条评论中提到了这一点@ani5ha
app.controller('myFriendController', function($scope, SelectedFriend) {
   // ...

   $scope.selectInfo = function(friend) {
     SelectedFriend.setFriend(friend);
   }
});

app.controller('myProfileController', function($scope, SelectedFriend) {
    $scope.myprofile = SelectedFriend;
});