我的a
標籤有問題 - 我有一個頁面,根據GET
變量顯示數據。AngularJS:如何使用ui-router爲我的應用創建路由
例如 - /foo.php?opt=1將顯示每個城市的表格 - /foo.php?city=4有/學校表的表格/foo.php?school= 4,顯示學生的表格等。
問題是,它第一次工作 - 當我選擇城市時,它會顯示我的學校列表和更改網址,但是當我選擇學校時,它會更改URL但我仍然可以看到城市桌,只有按F5鍵,纔會顯示桌上的學生。
這是代碼:
odinvite.php:
<?php
if (isset($_GET['city']))
{
include "odbycity.php";
}
else if (isset($_GET['school']))
{
include "odbyschool.php";
}
else
{
include "odshowcities.php";
}
?>
odshowcities.php:
<div ng-controller="allcities">
<button class="btn btn-info" ng-repeat="x in names">
<a href="/odinvite.php?city={{x.areaid}}">
{{x.areaname}}</a>
</button>
</div>
odbyschool.php:
<div ng-controller="odbycity">
<button class="btn btn-info" ng-repeat="x in names">
<a href="/odinvite.php?school={{x.schoolid}}">
{{x.school_name}}</a>
</button>
</div>
MyAngular.js:
var myApp = angular.module('myApp',[]);
myApp.config(function($locationProvider) {
$locationProvider.html5Mode(true);
});
myApp.controller ('allcities', function ($scope, $http)
{
$http.get("fetch_json_sql.php?option=1")
.then(function (response)
{
$scope.names = response.data.result;
});
console.log($scope.names);
});
myApp.controller ('odbycity', function ($scope, $http, $location)
{
$scope.cityid=$location.search().city;
console.log($scope.cityid);
$http.get("fetch_json_sql.php?option=2&cityid="+$scope.cityid)
.then(function (response)
{
$scope.names = response.data.result;
});
});
myApp.controller ('odbyschool', function ($scope, $http ,$location)
{
$scope.schoolid = $location.search().school;
console.log($scope.schoolid);
$http.get("fetch_json_sql.php?option=4&schoolid="+$scope.schoolid)
.then(function (response)
{
$scope.names = response.data.result;
});
});
可能是什麼問題?
我試圖做出100%的URL更改 - <a href="www.google.com">link</a>
並沒有奏效。只是改變了網址而沒有重定向。
謝謝!
請添加您的路線配置。 – lin
@lin只需添加它即可。 –
m8,AngularJS適用於SPA。將路由與後端直接結合起來並不那麼容易。你應該使用ngRoute或者uiRouter,而不需要你的模板被後端渲染。我仍然看不到'/odinvite.php? school'或'odinvite.php?city'的路線配置。你的問題是「爲什麼我的路線不能正常工作」。 – lin