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 AngularJS Basics (1.x) Controllers and Scope Creating a Controller

Jannatul Mou
Jannatul Mou
72 Points

My function is not called from the controller with the help of ng-click. What can I do?

app.js:

angular.module("todoListApp", []).controller('mainCtrl', function($scope){
  $scope.helloWorld=function(){
    console.log("Hay this is my controller from where I want to inject");
  };
});

index.html:

<!doctype html>
<html lang="en">
<head>
  <title></title>
  <link href='https://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
  <link href='styles/main.css' rel='stylesheet' type="text/css">
</head>
<body ng-app="todoListApp">
  <h1>My TODOs</h1>
  <div ng-contoller="mainCtrl" class="list">
    <input type="checkbox"/>
      <label class="editing-label">My editing level</label>
      <input class="editing-label" type="text"/>
      <div class="actions">
        <a href="">edit</a>
        <a href="" ng-click="helloWorld()">save</a>
        <a href="" class="delete">delete</a>
      </div>
  </div>

  <script src="vendor/angular.js" type="text/javascript"></script>
  <script src="scripts/app.js" type="text/javascript"></script>

</body>
</html>

4 Answers

Tommy Gebru
Tommy Gebru
30,164 Points

Hey Jannatul,

Haven't done this yet, but it is possible there is a typo for the class, ng-contoller="mainCtrl"

hope that helps :smile:

Jason S
Jason S
16,247 Points

hey, you spelled controller wrong here

<div ng-contoller="mainCtrl" class="list">
Jannatul Mou
Jannatul Mou
72 Points

Thanks for your kind help Jason S

ng-controller is spelt wrong ... it is ng-controller not ng-contoller

Jannatul Mou
Jannatul Mou
72 Points

It's not helping.... :(

Tommy Gebru
Tommy Gebru
30,164 Points

were you able to "ask" other students at the bottom of this page?

he might have forgotten to save the file before previewing but that seems to be the only problem was the typo for controller