如何解决TypeError:Object [object Object]没有方法'on'

时间:2014-01-17 06:41:26

标签: html5 angularjs

当我在Html中包含WYSIWYG编辑器时。我收到了这个错误,我还包括了我需要的所有js文件。

xyz.html

<html>
<head>

    <script src="js/angular/angular.min.js"></script>
            <script src="js/angular/textAngular.min.js"></script>
            <script src="js/angular/angular-sanitize.min.js"></script>
</head>
<body>
    <div text-angular ng-model="htmlcontent" name="htmlVariable"></div> 
</body>
</html>

Anglar.js模块

var myapp = angular.module('angularProject', ['textAngular'])

发生的错误如下。

TypeError: Object [object Object] has no method 'on'
    at link (http://localhost/englishPT/web/app/js/angular/textAngular.min.js:1:11164)
    at j (http://localhost/englishPT/web/app/js/angular/angular.min.js:43:458)
    at e (http://localhost/englishPT/web/app/js/angular/angular.min.js:39:248)
    at http://localhost/englishPT/web/app/js/angular/angular.min.js:38:312
    at link (http://localhost/englishPT/web/app/js/angular/textAngular.min.js:1:8160)
    at j (http://localhost/englishPT/web/app/js/angular/angular.min.js:43:458)
    at e (http://localhost/englishPT/web/app/js/angular/angular.min.js:39:248)
    at e (http://localhost/englishPT/web/app/js/angular/angular.min.js:39:265)
    at http://localhost/englishPT/web/app/js/angular/angular.min.js:38:312
    at updateView (http://localhost/englishPT/web/app/js/angular/angular-ui-router.js:1320:11) <div contenteditable="true" ng-hide="showHtml" ta-bind="text" ng-model="text" class="ng-isolate-scope ng-scope ng-pristine ng-valid"> angular.min.js:62
TypeError: Object [object Object] has no method 'on'
    at link (http://localhost/englishPT/web/app/js/angular/textAngular.min.js:1:8435)
    at j (http://localhost/englishPT/web/app/js/angular/angular.min.js:43:458)
    at e (http://localhost/englishPT/web/app/js/angular/angular.min.js:39:248)
    at e (http://localhost/englishPT/web/app/js/angular/angular.min.js:39:265)
    at http://localhost/englishPT/web/app/js/angular/angular.min.js:38:312
    at updateView (http://localhost/englishPT/web/app/js/angular/angular-ui-router.js:1320:11)
    at http://localhost/englishPT/web/app/js/angular/angular-ui-router.js:1285:9
    at j (http://localhost/englishPT/web/app/js/angular/angular.min.js:43:458)
    at e (http://localhost/englishPT/web/app/js/angular/angular.min.js:39:116)
    at http://localhost/englishPT/web/app/js/angular/angular.min.js:38:312 <text-angular ng-model="htmlcontent" name="htmlVariable" class="ng-isolate-scope ng-scope ng-pristine ng-valid ta-root"> 

2 个答案:

答案 0 :(得分:0)

检查您的angular.js版本和angular-sanitize.js兼容版本 (等等AngularJS v1.2.10和Angular-Sanitize v1.2.11将一起玩)

答案 1 :(得分:0)

在其他情况下,如果您在AngularJS中使用不兼容的jQuery版本,也可能发生这种情况。

来自AngularJS FAQ

  

Angular是否使用jQuery库?

     

是的,Angular可以在应用程序被引导时在您的应用程序中使用jQuery。如果你的脚本路径中没有jQuery,Angular会回退到我们称之为jQLite的jQuery子集的实现。

     

由于更改使用on()/ off()而不是bind()/ unbind(),Angular 1.2仅适用于jQuery 1.7.1或更高版本。