我已经创建了一个具有 2 种方法的 Web 服务,一般方法和详细信息方法。 General 显示基本数据,而 details 提供有关所选对象的更多详细信息。我发现在加载显示详细信息的新页面时遇到困难。
这些是我创建的 Angular 方法。
var app = angular.module("myModule", .....);
var app = angular.module("myModule2", [])
.controller("myController2", function ($scope, $http) {
$scope.test = "DetailsScript";
//method to get booking by reference start
$scope.getReference = function (Reference) {
$http({
method: 'GET',
url: 'http://localhost:3466/MyWebService.asmx/DashboardDetail',
params: {
Reference: Reference
}
}).then(function (response) {
$scope.booking = response.data
});
};
//method to get booking by reference end
//method to load page start
$scope.loadView = function (ref) {
var url = 'DetailsPage.html';
$scope.getReference(ref);
window.location(url);
};
//method to load page end
});
angular.module("CombineModule", ["myModule", "myModule2"]);
当我点击以下按钮时,我似乎无法获取详细信息以转到新页面:
<input id="refBox" type="text" ng-model="Reference" ng-change="getReference(Reference)" />
<br />
<input type="button" ng-click="loadView(Reference)" />
ng-click 只是将我带到新页面而没有加载新数据。
我的 Web 服务被正确调用并返回正确的 Context.Response.Write(javascriptserializer.Serialize(myObject));
可能有两个问题:页面在返回数据之前加载显示,因为它是异步的,如果是这样,为什么?当 loadView 调用具有 .then 函数的 getReference 时?
附言我是 angularjs 的新手。
最佳答案
这不是 Angular 的工作方式。 angular 背后的一般概念是你
- 加载页面(应用程序)
- 加载应在该页面上显示的所有数据
- 在 View 上显示数据
所以您的方法的问题是,您正在加载数据然后离开应用程序(通过转到 DetailsPage.html)。你不会那样做。
如果你想显示详细信息页面,你应该看看 ngRoute。
关于javascript - 数据未显示在新页面上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34681242/