-1
<html ng-app="myApp">
<head>
<script src=angular.js></script>
<script src=app.js></script>
</head>
<body>
<div ng-controller="mainController">
{{name}}
</div>
</body>
</html>

app.js file

angular.module('myApp',[]);
var mainController = function($scope){
$scope.name="peter";    
}

I must get a return of name "peter" but unfortunately I am not getting that. Can someone help me out?

Deadpool
  • 7,811
  • 9
  • 44
  • 88

2 Answers2

1

Modify your app.js as below:

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

app.controller('mainController', [$scope, function($scope) {
    $scope.name="peter"; 
}]);
Arulkumar
  • 12,966
  • 14
  • 47
  • 68
0

Change your controller to be dependent on module

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

app.controller('mainController', ['$scope', function($scope) {
    $scope.name="peter"; 
}]);

here is the workin Plnker

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396