我有一个使用AngularJS(AngularJS v1.3.0-beta.3)开发的应用程序,在IE10兼容模式下会崩溃。在Firefox、Chrome和IE11中都运行良好。以下是控制台报告的错误信息:
Multiple directives [login, login] asking for 'login' controller on: <div>
为了设置应用程序的状态,我创建一个节点:
link: function ($scope, $element, $attrs) {
....
$element.html('<login></login>');
$compile($element.contents())($scope); // crash happens here
....
}
这是我的登录指令:
widgets.directive('login', ['$compile', '$http', 'resourceLoader', function ($compile, $http, resourceLoader) {
return {
restrict: 'AE',
replace: true,
template: '<div></div>',
controller: function ($scope, $element) {
$scope.user.isLogged = false;
$scope.user.password = undefined;
$scope.submitLogin = function () {
// code that goes to server
};
},
link: function ($scope, $element, $attrs) {
resourceLoader.get('templates', 'profile', 'unlogged/login', 'jquery.min', function (template) {
$element.html(template);
$compile($element.contents())($scope);
});
}
};
}]);
任何想法?谢谢。