Angularjs directive does not work "Unexpected Token"

So, I am using 1.20 rc2 and trying to implement the directive:

var directives = angular.module('directives', ['controllers']); directives.directive("drink", function() { return { template: '<div>{{flavor}}</div>', link: function(scope){ scope.flavor = "cherry"; } } }); 

the directive is called in the main JS file

  var comsumerApp = angular.module('comsumerApp', ['ngRoute','controllers', 'services', 'directives']); 

All controllers work the same way as services, but when I try to do this, I get this error:

"Uncaught SyntaxError: Unexpected token:"

then i get

$ injector: modulerr error.

Commenting on the drink directive stops this error, so obviously this has something to do with: or something.

Can anyone highlight this problem, I completely lost.

Thanks.

+4
source share
1 answer

Try removing the line break before the opening bracket:

 return { template: '<div>{{flavor}}</div>', link: function(scope){ scope.flavor = "cherry"; } } 

:

 return { template: '<div>{{flavor}}</div>', link: function(scope){ scope.flavor = "cherry"; } } 

Perhaps this is due to the automatic semicolon insertion , so your browser inserts ; after return , because he thinks you just missed it.

+12
source

Source: https://habr.com/ru/post/1502163/


All Articles