简体   繁体   中英

AngularJS simple ng-controller error

I am learning angularJS, ng-app works ng-model works, but when I try ng-controller , it does not work, the fault is on my side but I am unable to figure out what it is, I am not even trying anything fancy, just trying make the ng-controller work,

what is my mistake in the below code?

HTML :

<div ng-app="">
    <h1 ng-controller="HelloWorldCtrl">{{helloMessage}}</h1>
</div>`

and JS :

function HelloWorldCtrl($scope){
    $scope.helloMessage="Hello World";
}

same problem when run in jsfiddle

 var myapp = angular.module('myApp', []); myapp.controller('HelloWorldCtrl', function($scope){ $scope.helloMessage = "Hello world"; }) 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="myApp"> <h1 ng-controller="HelloWorldCtrl">{{helloMessage}}</h1> </div> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM