對於AngularJS來說,這是相當新穎的。 我寫了一個代碼,它的工作正常。 想知道,是否有辦法進一步縮小控制器。 我index.html文件是AngularJS中的標準化控制器
<!DOCTYPE html>
<html lang="en-US">
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<input type="text" ng-model="sea" ng-change="newSearch()"/>
<ul>
<li ng-repeat="x in myData">
{{ x.name + ', ' + x.emailid}}
</li>
</ul>
</div>
<script src="js/app.js"></script>
<script src="js/controllers/maincontroller.js"></script>
</body>
</html>
而且maincontroller.js是
app.controller('customersCtrl', function($scope, $http) {
$http(
{
url: "http://localhost:8080/cordovaprojects/123m/www/customer.php",
method: "GET",
params: {'name':'powercom'}
})
.then(function(response) {
$scope.myData = response.data.records;
});
$scope.newSearch = function() {
$scope.newSea = $scope.sea;
$http(
{
url: "http://localhost:8080/cordovaprojects/123m/www/customer.php",
method: "GET",
params: {'name':$scope.newSea}
})
.then(function(response) {
$scope.myData = response.data.records;
});
};
});
如果您發現我已經使用了相同的$http
函數的param
相差兩倍。
謝謝。
保持乾燥,你也許應該關閉或$ HTTP投入運營至少一個功能 – maurycy
這個問題更適合[代碼評論](http://codereview.stackexchange.com/) – topher