Search code examples
javascriptphpangularjscodeigniter-3textangular

AngularJS' ng:areq Bad Argument "{controller} is not a function", with textAngular on CodeIgniter


I'm trying to implement a text editor with textAngular in a CodeIgniter view, but it keep returning this error:

angular.js:13424 Error: [ng:areq] Argument 'wysiwygeditor' is not a function, got undefined
http://errors.angularjs.org/1.5.3/ng/areq?p0=wysiwygeditor&p1=not%20a%20function%2C%20got%20undefined

Where 'wysiwygeditor' is the name on ng-controller.

I've found tens of questions about that, and all seems to be caused by the same mistakes:

  • Unnamed ng-app directive
  • Omitted second argument on module definition angular.module('myApp', [])
  • Version incompatibilities on controller declaration

None of those happens to be the problem, and I'm simply copying a code that already works. It's the demo.html from textAngular-1.5.0. I copy the code to a CodeIgniter view, include all the required libraries, but still get the error. Then I noticed it's happening whenever I declare a controller with Angular JS.

To make a better example:

<script src='https://ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js'></script>
<div ng-app="myApp">
    <div ng-controller="GreetingController">
        {{greeting}}
    </div>
</div>
<script>
    var myApp = angular.module('myApp',[]);

    myApp.controller('GreetingController', ['$scope', function($scope) {
      $scope.greeting = 'Bom dia!';
    }]);
</script>

This code gives that error on CodeIgniter, but if I put it in a simple html file, works normally.


Solution

  • My fault, my project was declaring an ng-app on a parent element, in a template file that I've forgot that existed. Removed this tag, and AngularJS stop returning that error.