Madhur Ahuja
Madhur Ahuja

Reputation: 22681

Error in simple directive

I am learning Angular and was trying to create a simple directive given in a book. The code is given below.

I am getting the error, Uncaught SyntaxError: Unexpected token : on line
template: '<div>Hi there </div>',

I just can't figure out what is wrong. Can you ?

<html ng-app="app">
<head>
<script src="angular.js" type="text/javascript"></script>
<script type="text/javascript">

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

appModule.directive('hello', function()
{

    return 
    {
        restrict: 'E',
        template: '<div>Hi there </div>',
        replace: true
    };

});

</script>
</head>

<body>

    <hello></hello>


</body>

</html>

Upvotes: 0

Views: 39

Answers (1)

runTarm
runTarm

Reputation: 11547

Change this

return 
{

to this

return {

Explanation: In the first case, when the { is on a different line. It actually mean return undefined, follow by an unreachable block statement. And in the block there is a syntax error.

Upvotes: 3

Related Questions