0

I just started AngularJS today; so I'm still very new to it. I have the following code:

<!DOCTYPE html>
<html ng-app>
<head>
    <title>My first AngularJs</title>
</head>
</html>
<body data-ng-controller="SimpleController">

<div class="container"> 
<h3>Looping with the ng-repeat Directive</h3>

<input type="text" ng-model="nameText"/>{{ nameText}}
<ul>
    <li data-ng-repeat="cust in customers | filter:nameText | orderBy:'name'">{{ cust.name | uppercase }} - {{ cust.city}}</li>
</ul>
</div>
<script type="text/javascript" src="angular.min.js"></script>

<script type="text/javascript">
function SimpleController($scope){
    $scope.customers=[
        {name:'Frank Ben',city:'Bamenda'},
        {name:'Brize Tankanon',city:'Marous'},
        {name:'Brendaline M.',city:'Bafoussam'},
        {name:'Alexander Bings',city:'Buea'}
    ];
}

When I run the above code, this is what I get:

Screenshot with the controller

when I remove the controller directive from the body tag, I get this:

Screenshot without the controller

I don't know where the problem is coming from. I wish to display those names and cities. I will be grateful for your help. Thanks!

1
  • In such situations you must looked up Console of browser for some errors in ClientSide Commented May 26, 2016 at 15:59

1 Answer 1

2

Try to register controller in angularjs app using build in dependency injection, in other words:

<script type="text/javascript">
  var app = angular.module("app", []);

app.controller('SimpleController', ['$scope', function SimpleController($scope){
    $scope.customers=[
        {name:'Frank Ben',city:'Bamenda'},
        {name:'Brize Tankanon',city:'Marous'},
        {name:'Brendaline M.',city:'Bafoussam'},
        {name:'Alexander Bings',city:'Buea'}
    ];
}]);

  </script>

then change ng-app to ng-app="app".

Here is JSBin with working example: http://jsbin.com/ficozajena/1/edit?html,js,output

Sign up to request clarification or add additional context in comments.

3 Comments

It works perfectly! Tthe book I'm using is old probably. From the video that accompanies the book, everything works. The changes @csharpfolk recommends works perfectly. I'm happy!
@FrankFotangs Be sure to mark their response as the answer to your question.
Yeah! I wanted to but the system says I wait!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.