Angular 1 cannot load module / controller file in view / html

var myApp = angular.module("myModule",[]);
myApp.controller("myController",function($scope){
    $scope.name = "Hello Anjnee";
});


<html>
    <head>
        <script src="Scripts/script.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
    </script>
    </head>
    <body ng-app="myModule">
        <div ng-controller="myController">
        <p>{{name}}</p>
    </div>
</body>
</html>

      

I am trying to use the value of $ scope.name in a html page. I kept both .js and .html files separately.

+3


source to share


2 answers


Have you had any browser error messages? The code looks good. Perhaps it comes from the angular.min.js CDN being called in the head. I think you should put it before your script.js file because script.js is being referenced by angular which hasn't loaded yet.

Also, in your head you wrote:

<head>`enter code here`</head>.

      



You should comment "enter code here" according to the way to comment out code in html like this:

<!-- enter code here -->

      

Otherwise, folder scripts start with an uppercase. I suggest you write it entirely in uppercase or completely in lowercase to make it more readable and less confusing.

0


source


You need to pass $ scope as a dependency of your controller. Start declaring your controller like this:



myApp.controller('myController', ['$scope', function($scope) {

      

0


source







All Articles