Search code examples
angularjsangular-ng-ifangularjs-digest

Angular digest - TypeError: v12 is not a function


I'm using AngularJs 1 in a project. I've noticed that sometimes I get the error

TypeError: v12 is not a function. (In 'v12(v16)', 'v12' is false)
fn
$digest — angular.js:18363
$apply — angular.js:18640
done — angular.js:12618
completeRequest — angular.js:12862
requestLoaded — angular.js:12779
undefined
(funzione anonima) — angular.js:11209
(funzione anonima) — angulartics.js:425
$digest — angular.js:18389
$apply — angular.js:18640
done — angular.js:12618
completeRequest — angular.js:12862
requestLoaded — angular.js:12779
angular.js:11209

in the console and I don't understand what it is related to.


I don't know if it's related, but some ng-if don't work (just some).

It's strange because the code

<div ng-if="isAdmin">Am I Admin? {{isAdmin}}</div>

shows

Am I Admin? false

Further details

That code is contained in a template of a custom directive

.directive('myDirective', function() {   return {
    replace    : true,
    restrict   : 'E',
    scope      :
      {
          /* -------
           &    : function
           @    : 1-way
           =    : 2-ways
          ---------*/
          isAdmin          : '@'

used as follow

<my-directive  is-admin="{{ctrl.isAdmin}}">
</my-directive>

Solution

  • I found what's wrong, it's the symbol used in parameters passed to the directive.

    I used

    // directive spec
    .directive('myDirective', function() {   return {
        scope      :
          {  isAdmin : '@' }
    
    // directive usage
    <my-directive  is-admin="{{ctrl.isAdmin}}">
    </my-directive>
    

    but the correct way is

    // directive spec
    .directive('myDirective', function() {   return {
        scope      :
          {  isAdmin : '=' }
    
    // directive usage
    <my-directive  is-admin="ctrl.isAdmin">
    </my-directive>
    

    Since @ it's 1 way, while = is 2 ways. So I guess using @ the boolean values are converted into a string. With = everything works. By the way I really don't know why I got that weird error TypeError: v12 is not a function. (In 'v12(v16)', 'v12' is false)