0

When i am using angular version this. "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0-rc.2/angular.js" my code works fine. but when i am using this angular version my code is not working. "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js".

Full HTML code.

 <!DOCTYPE html>
 <html ng-app="">
 <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
 <head>
 <title>Angular Js Tutorial</title>
 </head>
 <body>
 <div ng-controller="Maincontroller">
 {{message}}
 </div>
 <script>
 function Maincontroller($scope)
 {
 $scope.message = "Hii how are you";
 }
 </script>
 </body>
 </html>

I didn't the required output. It simply prints.

 {{message}}
asked Nov 21, 2015 at 15:24
2

4 Answers 4

3

Starting from angular 1.3 you can't declare controllers in the global scope.

Rewrite the declaration of your controller MainController

// Declaration of the module
angular.module('myApp', []);
// Declaration of the controller
angular.module('myApp').controller('MainController', function ($scope) {
 $scope.message = "Hii how are you";
});

Regarding to the above changes, replace <html ng-app=""> with <html ng-app="myApp">

answered Nov 21, 2015 at 15:31
Sign up to request clarification or add additional context in comments.

1 Comment

Great ! i have posted the same below
1

There are few problems with your code,

(i)You have not declared module anywhere. (ii) With Angular 1.3 you the controllers should not be declared globally.

Here is the corrected application

answered Nov 21, 2015 at 15:32

Comments

0
<!DOCTYPE html>
<html ng-app="app">
 <head>
 <title>Angular Js Tutorial</title>
 <script src= "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
 </head>
 <body >
 <div ng-controller="MainController as mainCtrl">
 {{ mainCtrl.message }}
 </div>
 <script>
 (function() {
 'use strict';
 angular
 .module('app', []);
 .controller('MainController', ['$scope', function MainController($scope) {
 $scope.message = "Hii how are you";
 }]);
 })();
 </script>
 </body>
</html>

Please refer this.

answered Nov 21, 2015 at 15:46

1 Comment

If you are using MainController as mainCtrl, don't use $scope. Use this.
-1
<html>
<head>
<title>Angular JS Controller Example</title>
<script src= "https://ajax.googleapis.com/ajax/libs/angularjs/
1.4.7/angular.min.js"></script>
</head>
<body>
<h2>AngularJS Sample Controller Application</h2>
<div ng-app = "ukApp" ng-controller = "ukController">
<br> 
{{name}}
</div>
<script>
var mainApp = angular.module("ukApp", []);
mainApp.controller('ukController', function($scope) { 
$scope.name= "Umar Farooque Khan";
});
</script>
</body>
</html>

Use the above code to do above task.

Martijn Pieters
1.1m326 gold badges4.2k silver badges3.4k bronze badges
answered Aug 17, 2016 at 17:31

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.