我的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