0

In my angular code, in provider showing some error unexpected token

var app= angular.module('myapp',[]);


app.provider('date',function() {
    return {
        $get:function()
        {
            return
            {
                    showDate:function()
                    {
                        return 4;
                    }
            }
        }
    }

);
Alon Eitan
  • 11,997
  • 8
  • 49
  • 58
  • Seeing the first return statement inside $get makes me wince. See this [topic](http://stackoverflow.com/questions/18221963/javascript-function-fails-to-return-object-when-there-is-a-line-break-between-th). – Cosmin Ababei Mar 15 '16 at 10:02

2 Answers2

2

You forgot to close your first function with a '}'

var app= angular.module('myapp',[]);


app.provider('date',function() {
    return {
        $get:function()
        {
            return
            {
                showDate:function()
                {
                    return 4;
                }
            }
        }
    }
});
JulCh
  • 2,710
  • 2
  • 19
  • 21
1

Javascript will automatically insert a semicolon after your second return statement. Try

return {
   showDate:function()
   {
        return 4;
   }
}

Working JSFiddle (Combined with JulCh's answer): https://jsfiddle.net/qs6ufoo3/

henrikmerlander
  • 1,554
  • 13
  • 20