0

my controller.js file

function ServicesCtrl($scope) {
    console.log("Hello From ServicesCtrl");
    $scope.message = "Hello";       
} 

index.html file

<html>
<head>
    <title>The MEAN Stack</title>
    <link href="css/bootstrap.css" rel="stylesheet" />
    <script src="js/angular.min.js"></script>
    <script src="features/services/controller.js"></script>
</head>

<body ng-app="">
    <div class="container" ng-controller="ServicesCtrl">
        <h1>Service Client Maker</h1>
        {{message}}
    </div>
</body>
</html>

it is not displaying my message. controller.js file is not accessable

ranakrunal9
  • 13,320
  • 3
  • 42
  • 43
Abdul Hannan
  • 21
  • 1
  • 1
  • 3
  • You have to create an angular module first and add controller to that module, look at [this answer](http://stackoverflow.com/a/28728380/2435473) would help you.. – Pankaj Parkar Jan 16 '17 at 09:34
  • You should look at the first two getting started pages on the angularjs official page. – YannickHelmut Jan 16 '17 at 09:34

3 Answers3

1

Its clear that you are trying to define a controller like a simple js function. But, It works in a different way.
You have to initialize an angular app within an java-script variable like this,

var app=angular.module("MyApp");

and handle that entire angular application, through that js variable "app".

I strongly recommend you to completely go through below tutorials.. Then, Start creating the App..

https://www.tutorialspoint.com/angularjs/angularjs_mvc_architecture.htm http://www.w3schools.com/angular/default.asp

0

You have to define your angular application and its modules.

var app = angular.module('myApp');

app.controller('serviceController', function() {
    $scope.message = "Nice, I now know how to create an angular app";
})

And you will now be able to access it on your page:

<body ng-app="myApp">...
    <div ng-controller="serviceController">...
        {{message}}

This should help you since you're getting started with angular.

YannickHelmut
  • 555
  • 1
  • 7
  • 20
0

Here this example define your controller name (controller.js)

var app = angular.module('myApp', []);
app.controller('ServicesCtrl', function($scope) {
    $scope.message = "Hello";
});

define your app name (index.html)

<body ng-app="myApp">
    <div class="container" ng-controller="ServicesCtrl">
        <h1>Service Client Maker</h1>
        {{message}}
    </div>
</body>
Thailand
  • 93
  • 1
  • 2
  • 10