【发布时间】:2017-04-02 08:32:20
【问题描述】:
我的a 标记有问题 - 我有一个根据GET 变量显示数据的页面。
例如 - /foo.php?opt=1 将显示每个人将去的城市表 - /foo.php?city=4 有去 /foo.php?school=4 的学校表显示学生表等。
问题是它第一次工作 - 当我选择城市时,它会显示学校列表并更改 url,但是当我选择学校时,它会更改 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;
});
});
可能是什么问题?
我尝试对 URL 进行 100% 更改 - <a href="www.google.com">link</a>,但没有成功。只是更改了没有重定向的 URL。
谢谢!
【问题讨论】:
-
请添加您的路由配置。
-
@lin 只需添加它.. 可以吗?
-
嗯 m8,AngularJS 是用于 SPA 的。直接将您的路线与后端结合起来并不容易。您应该使用 ngRoute 或 uiRouter 而不让后端呈现您的模板。我仍然看不到
/odinvite.php?school或odinvite.php?city的路由配置。您的问题是“为什么我的路线不起作用”。 -
这就是我所有的代码......我刚刚开始学习 AngularJS。关于这条路线,我需要了解什么?
-
这是我的解决方案...? - docs.angularjs.org/api/ng/directive/ngHref