Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

brandonlind2
brandonlind2
7,823 Points

why isnt my first simple angular app working?

<!DOCTYPE html>
<html>
    <head>
    <title>test</title>
    <charset="utf-8">
    <style>
    p { background-color: blue;
        width: 5px;
        height: 5px;}
    </style>
    </head>
    <body ng-testApp>
        <header>
            <nav>
                <a href="index.html">Home</a>
                <a href="page2.html"> Page2</a>
                <a href="page3.html">Page3</a>
                <a href="Page4.html">Page4</a>
            </nav>
        </header
        <section ng-controller="mainCtrl">
        <p ng-click>this is ap tag</p>
        </section>
        <footer>
        </footer>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
        <script type="text/javascript" src="script.js"</script>
    </body>
</html>
angular.module("testApp",[]).controller('mainCtrl', function($scope){
        $scope.helloWorld= function(){
         console.log('hello world');

        }
    }
}

1 Answer

David Bath
David Bath
25,940 Points

It's not working because ng-testApp is not an AngularJS directive. You should change the body tag to

<body ng-app="testApp">