AngularJSを初めて使用しています。AngularJS - ngViewを使用するとHTMLページに返信されたデータが表示されない
私はSQLデータベースを使用したPHPサーバーを持っていますが、AngularJSと$ http get要求をサーバーに送信するボタンを持つhtmlページがあり、これは同じサーバー上のテーブルに表示されるデータの配列を返しますページ。
websitename/myList.htmを直接開いてgetListを押すと、データは問題なく完全に表示されますが、ngViewルーティングでページを開くとページ要素が表示されますが、ボタンを押すと、サーバーからのデータでページが更新されません。
2つのページの間に追加のデータリンクが必要ですか?ルートと
myList.htm
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
<script>
angular.module("crudApp", [])
.controller("userController", function($scope,$http){
$scope.users = [];
$scope.tempUserData = {};
// function to get records from the database
$scope.getList = function(){
$http.get('action.php', {
params:{
'type':'getList'
}
}).success(function(response){
if(response.status == 'OK'){
$scope.users = response.records;
}
});
};
});
</script>
<body ng-app="crudApp">
<div class="container" ng-controller="userController">
<a href="javascript:void(0);" class="btn btn-success" ng-click="getList()">getList</a>
<table class="table table-striped">
<tr>
<th width="20%">Name</th>
<th width="30%">Email</th>
<th width="20%">Phone</th>
</tr>
<tr ng-repeat="user in users">
<td>{{user.Name}}</td>
<td>{{user.Email}}</td>
<td>{{user.Phone}}</td>
</tr>
</table>
<p>end of table</p>
</body>
</html>
ページ:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script>
<body ng-app="myApp">
<p><a href="#/">Main</a></p>
<a href="#list">List</a>
<div ng-view></div>
<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/list", {
templateUrl : "myList.htm"
});
});
</script>
<p>Click on the links to navigate</p>
</body>
</html>
ありがとうございます。
私たちにいくつかのコードを見せてください –