Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
134
rated 0 times [  140] [ 6]  / answers: 1 / hits: 38832  / 7 Years ago, tue, february 7, 2017, 12:00:00

i have this code in my script.js file



var mainController = function($scope){
$scope.message = Plunker;
};


and this is my HTML



<!DOCTYPE html>
<html ng-app>
<head>
<script [email protected] data-semver=1.6.1 src=https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.js></script>
<link rel=stylesheet href=style.css />
<script src=script.js></script>
</head>

<body ng-controller=mainController>
<h1>Hello {{ message }}</h1>
</body>
</html>


i declared ng-app in the opening html tag



but i get this error on my console that mainController is not registered


More From » angularjs

 Answers
1

To paraphrase http://www.w3schools.com/angular/angular_modules.asp



 <div ng-app=myApp ng-controller=mainController>
{{ firstName + + lastName }}
</div>

<script>

var app = angular.module(myApp, []);

app.controller(mainController, function($scope) {
$scope.firstName = John;
$scope.lastName = Doe;
});

</script>


The important line is



    app.controller(mainController, function($scope) 


which injects your controller into your app


[#59048] Saturday, February 4, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stefanicarolinat

Total Points: 145
Total Questions: 91
Total Answers: 93

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
stefanicarolinat questions
Mon, Nov 15, 21, 00:00, 3 Years ago
Fri, Apr 16, 21, 00:00, 3 Years ago
Thu, Oct 15, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
;