Javascript 如何恢复angularJS中单击的变量

Javascript 如何恢复angularJS中单击的变量,javascript,angularjs,Javascript,Angularjs,当我点击按钮时,只需恢复(在“myfunction”中)我行上的变量“name” 这是我的索引页 <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="customer

当我点击按钮时,只需恢复(在“myfunction”中)我行上的变量“name”

这是我的索引页

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>


<div ng-app="myApp" ng-controller="customersCtrl"> 

<table>
    <tr>
    <th>Nom</th>
    <th>Pays</th>
    <th>Ville</th>
    <th>button</th>
    </tr>
    <tr ng-repeat="x in myData">
    <td value="{{x.Name}}">{{ x.Name | uppercase }}</td>
    <td>{{ x.Country }}</td>
    <td>{{ x.City }}</td>
    <td><button ng-click="myFunction()">Click me!</button></td>
    </tr>
</table>

</div>

<script src="Ctrl.js"></script>

</body>
</html>
这是我的php文件

{ "records":[ {"Name":"Alfreds Futterkiste","City":"Berlin","Country":"Germany"}, {"Name":"Ana Trujillo Emparedados y helados","City":"México D.F.","Country":"Mexico"}, {"Name":"Antonio Moreno Taquería","City":"México D.F.","Country":"Mexico"}, {"Name":"Around the Horn","City":"London","Country":"UK"}, {"Name":"B's Beverages","City":"London","Country":"UK"}, {"Name":"Berglunds snabbköp","City":"Luleå","Country":"Sweden"}, {"Name":"Blauer See Delikatessen","City":"Mannheim","Country":"Germany"}, {"Name":"Blondel père et fils","City":"Strasbourg","Country":"France"}, {"Name":"Bólido Comidas preparadas","City":"Madrid","Country":"Spain"}, {"Name":"Bon app'","City":"Marseille","Country":"France"}, {"Name":"Bottom-Dollar Marketse","City":"Tsawassen","Country":"Canada"}, {"Name":"Cactus Comidas para llevar","City":"Buenos Aires","Country":"Argentina"}, {"Name":"Centro comercial Moctezuma","City":"México D.F.","Country":"Mexico"}, {"Name":"Chop-suey Chinese","City":"Bern","Country":"Switzerland"}, {"Name":"Comércio Mineiro","City":"São Paulo","Country":"Brazil"} ] } 

提前感谢您的回复,

我认为您以自己的方式尝试了这件简单的事情,但由于输入错误,没有在控制器上的函数中获取任何数据:)

从HTML内部调用函数时犯了一个非常愚蠢的错误。您将其键入为
myFunction()
,其中,根据控制器的代码,调用名称应为
myFunction()

因此,下面的方法非常有效

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>


<div ng-app="myApp" ng-controller="customersCtrl"> 

<table>
    <tr>
    <th>Nom</th>
    <th>Pays</th>
    <th>Ville</th>
    <th>button</th>
    </tr>
    <tr ng-repeat="x in myData">
    <td value="{{ x.Name }}">{{ x.Name | uppercase }}</td>
    <td>{{ x.Country }}</td>
    <td>{{ x.City }}</td>
    <td><button ng-click="myfunction(x.Name)">Click me!</button></td>
    </tr>
</table>

</div>

<script src="Ctrl.js"></script>

</body>
</html>
Javascript区分大小写


您是否尝试在
myFunction()
中传递
x.Name
myFunction(x.Name)
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>


<div ng-app="myApp" ng-controller="customersCtrl"> 

<table>
    <tr>
    <th>Nom</th>
    <th>Pays</th>
    <th>Ville</th>
    <th>button</th>
    </tr>
    <tr ng-repeat="x in myData">
    <td value="{{ x.Name }}">{{ x.Name | uppercase }}</td>
    <td>{{ x.Country }}</td>
    <td>{{ x.City }}</td>
    <td><button ng-click="myfunction(x.Name)">Click me!</button></td>
    </tr>
</table>

</div>

<script src="Ctrl.js"></script>

</body>
</html>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
  $http.get("customers.php").then(function (response) {
      $scope.myData = response.data.records;
      console.log($scope.myData);
      $scope.myfunction = function(Name){
            console.log(Name);
      }
  });
});