我在 AngularJs 中使用 ControllerAs 语法。我面临的问题是,当其他 javascript 库调用并行运行的 jQuery 时,jQuery 库会引发错误,这会导致我的 ControllerAs 停止工作。请在下面找到我的代码
该代码在 Chrome 中正确运行,但在 IE 中不正确。
IE抛出的错误是
SCRIPT5022:InvalidCharacterError
chrome抛出的错误是
未捕获的 DOMException:无法在“元素”上执行“setAttribute”:“aria-expanded”不是有效的属性名称
我知道问题是要删除 aria-expanded 中的多余空格,但我无权更改该 javascript 库。
var stApp = angular.module("AngularApp",["ngRoute","ngSanitize","ui.bootstrap"]);
stApp.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "https://somedomain.com/sites/somesite/Assets/js/Application/sessions.html", controller:"appcontroller"
})
.when("/create", {
templateUrl : "https://somedomain.com/sites/somesite/Assets/js/Application/createnew.html", controller:"appcontroller"
})
.when("/editimage/id/:spot_event_id", {
templateUrl : "https://somedomain.com/sites/somesite/Assets/js/Application/editimage.html", controller:"appcontroller", controllerAs: 'stc'
})
.otherwise({ redirectTo: '/' })
});
stApp.controller('appcontroller', appcontroller);
function appcontroller($scope,$routeParams,$window,$timeout,$location,$uibModal,fileReader,SessionInfo){
var modal = this;
vm.ShowLoading = true;
/** Other Variables required are declared below which cannot be shown**/
SessionInfo.GetEventsInfoAsync($scope); // This functions performs a async call and the function utilizes $broadcast to trigger $scope.$on('asyncEventInfoResult')
$scope.$on('asyncEventInfoResult', function (event, data) {
$scope.$apply(function () {
data.Events.forEach(function(item,index){
var organizers = [];
item.Organizer.forEach(function(user,index){
organizers.push(user.get_lookupValue());
});
item.Organizers = organizers;
var sessionTime = new Date(item.StartTime);
var today = new Date();
if(sessionTime>today)
{
vm.Events.UpcomingEvents.push(item);
}
else
{
vm.Events.PastEvents.push(item);
}
});
vm.ShowLoading = false;
});
});
}