我在一个项目中使用 AngularJS,并尝试使用包含的路由进行导航。我在 IE7 和 8 中遇到问题。当我转到其中一个页面时,控制器会触发并加载数据。(我可以看到在填充了所有数据绑定字段的情况下返回了部分。)问题是部分没有被添加/附加到 ng-view。我开始使用 AngularJS v1.0.1 但现在切换到 1.0.2 认为这可能是我使用的版本中的一个错误。任何帮助将不胜感激。
这是我用于路由的代码:
myApp.config(['$routeProvider', function($routeProvider, $location){
$routeProvider.when('/business/:query', { templateUrl: 'partials/detail.html', controller: 'details'});
$routeProvider.when('', { templateUrl: 'partials/splash.html'});
$routeProvider.when('/results/:query', { templateUrl: 'partials/list.html', controller: 'listController'});
$routeProvider.otherwise({redirectTo: ''});
}]);
这是控制器的代码:
myApp.controller('listController', listController = function($scope, $routeParams, $http, $cookies){
var query = $routeParams.query;
var myQuery = query.indexOf('-') > 0 ? $scope.removeDashes(query):query;
switch($scope.selected)
{
case 'name':
$http({ method: 'jsonp',
//URL to test service
url: 'http://localhost:56119/PropertyAppraiser/PABusinessSearchService.asmx/searchBusinesses?NAME=' + myQuery + '&callback=JSON_CALLBACK',
header: { 'Content-Type': 'application/json; charset=utf-8' }
})
.success(function(data){
$scope.businesses = data;
});
break;
case 'address':
$http({method:'jsonp',
//URL to test service
url:'http://localhost:56119/PropertyAppraiser/PABusinessSearchService.asmx/searchAddress?myAddress=' + myQuery + '&callback=JSON_CALLBACK',
header:{'Content-Type':'application/json; charset=utf-8'}
})
.success(function(data){
$scope.businesses = data;
})
.error(function(data){
return false;
})
break;
}
})
myApp.controller('details', details = function($scope, $http, $routeParams){
var query = $routeParams.query;
var myQuery = query.indexOf('-') > 0 ? $scope.removeDashes(query):query;
$http({ method: 'jsonp',
//URL to test service
url: 'http://localhost:56119/PropertyAppraiser/PABusinessSearchService.asmx/searchBusinesses?FOLIO=' + myQuery + '&callback=JSON_CALLBACK',
header: { 'Content-Type': 'application/json; charset=utf-8' }
})
.success(function(data){
$scope.businesses = data;
});
});
这是应用程序的 HTML:
<div id="ng-app" class="ng-app:myApp ng-cloak" ng-cloak ng-app="myApp" ng-controller="businessSearchCtrl">
<div id="infoContainer" >
<h1 id="mainHeader">Personal Property Account Information</h1>
<div id="searchContainer">
<h3 style="background: none; margin: 0; padding: 0">Search By Folio, Business Name, or Address:</h3>
<select ng-model="chosen" ng-options="i.id as i.name for i in items">
<option value=""></option>
</select>
<input id="searchBox" type="text" placeholder="Enter Business Name or Folio Number" ng-model="query" />
<input id="submit" type="button" ng:click="search()" value="Search"/>
</div>
<div class="ng-view">
</div>
</div>
<div style="clear:both; height:0"> </div>
</div>
<div style="clear:both; height:0"> </div>
</div>
编辑:它适用于我测试过的所有其他浏览器,包括 IE9,我也没有收到任何错误消息。