Reputation: 61
Today I decided to try out some tricks of AngularJS! Can someone explain me what is the problem with my code? This example was shown in video I downloaded to learn Angular. When I try it, it shows me an error tip:
<html data-ng-app="">
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="angular.min.js"></script>
<script type="text/javascript" src="angular.min.js"></script>
<script>
function Test($scope){
$scope.persons =
[{name: 'Me', city:'Saint Pete'}, {name: 'Other', city:'Moscow'}]};
</script>
<title>
ANGULAR
</title>
</head>
<body>
<div data-ng-controller="Test">
<input type="text" data-ng-model="name">
<ul>
<li data-ng-repeat="person in persons | filter: name"> {{person.name}} - {{person.city}} </li>
</ul>
</div>
</body>
</html>
This is the error tip in the console: Error: [ng:areq] http://errors.angularjs.org/1.3.2/ng/areq?p0=Test&p1=not%20a%20function%2C%20got%20undefined at Error (native) at file:///C:/Program%20Files%20(x86)/EasyPHP-DevServer-14.1VC9/data/localweb/projects/angular/angular.min.js:6:416 at Nb (file:///C:/Program%20Files%20(x86)/EasyPHP-DevServer-14.1VC9/data/localweb/projects/angular/angular.min.js:19:417) at ob (file:///C:/Program%20Files%20(x86)/EasyPHP-DevServer-14.1VC9/data/localweb/projects/angular/angular.min.js:20:1) at file:///C:/Program%20Files%20(x86)/EasyPHP-DevServer-14.1VC9/data/localweb/projects/angular/angular.min.js:75:177 at file:///C:/Program%20Files%20(x86)/EasyPHP-DevServer-14.1VC9/data/localweb/projects/angular/angular.min.js:57:112 at r (file:///C:/Program%20Files%20(x86)/EasyPHP-DevServer-14.1VC9/data/localweb/projects/angular/angular.min.js:7:408) at I (file:///C:/Program%20Files%20(x86)/EasyPHP-DevServer-14.1VC9/data/localweb/projects/angular/angular.min.js:56:496) at g (file:///C:/Program%20Files%20(x86)/EasyPHP-DevServer-14.1VC9/data/localweb/projects/angular/angular.min.js:51:299) at g (file:///C:/Program%20Files%20(x86)/EasyPHP-DevServer-14.1VC9/data/localweb/projects/angular/angular.min.js:51:316)
Upvotes: 0
Views: 965
Reputation: 340
You have not added AngulaJS in your page. Just add the below line in head section.
<head>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
</head>
You could also download angularjs file and give its path.
Upvotes: 0
Reputation: 282
The ng-app tag should have a name, and your test definition should be as follow:
ng-app="mayApp"
angular.module ("myapp",[]) //definition of the angular module
your test should be defined as a controller as follow:
angular.module ("myapp").controller ("Test", function Test (){
//test function should go here.
});
Upvotes: 1