rendell
rendell

Reputation: 937

Error: [ng:areq] http://errors.angularjs.org/1.4.4/ng/areq?p0=FirstCtrl&p1=not%20a%20function%2C%20got%20undefined?

I'm new to angularjs and was wondering what's wrong with my code. I am following a tutorial but I got stuck because of this error.

index.php

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>AngularJS</title>
<link rel="stylesheet" href="foundation.min.css">
<script src="main.js"></script>
</head>
<body>

<div ng-app="">
    <div ng-controller="FirstCtrl">

    <h1>{{data.message + " world"}}</h1>
    <div class="{{data.message}}">
        Wrap me with foundation component
    </div>
    </div>
</div>

 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4 
 /angular.min.js"></script>
</body>
</html>

main.js

function FirstCtrl($scope){
  $scope.data = {message: "hello"};
}

Upvotes: 2

Views: 3571

Answers (1)

Ced
Ced

Reputation: 1301

You have to create a module, like this:

var app = angular.module("MyApp",[]);
app.controller("FirstCtrl",function($scope){
    $scope.data = {message: "hello"};
});



<div ng-app="MyApp">
    <div ng-controller="FirstCtrl">

    <h1>{{data.message + " world"}}</h1>
    <div class="{{data.message}}">
        Wrap me with foundation component
    </div>
    </div>
</div>

Upvotes: 3

Related Questions