0

See the image for the problem
angular.controller('myController', function ($scope) { var reg = { firstName: 'Aaa', lastName: 'Sss', }; $scope.reg = reg; }); This is my control.js file

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Script/angular.min.js"></script>
<script src="Script/ControllerOnly.js"></script>
</head>
<body>
<div ng-controller="myController">
    FirstName <input type="text" ng-model="reg.firstName" />
     <br />    
 LastName<input type="text" ng-model="reg.lastName" />
    <br />
    <br />
    {{reg.firstName}}
    <br />
    {{reg.lastName}}
    </div>
</body>
</html>

This is my html file.

Not getting the output and unable to decipher the error. Any help will be appreciated and thanks in advance..

2
  • you are missing ng-app in the html Commented May 26, 2016 at 7:30
  • I tried it, still not happening... Commented May 26, 2016 at 7:38

2 Answers 2

1

You were missing the ng-app in the html.

Please see this working fiddle : https://jsfiddle.net/r6ydu0p8/

Sign up to request clarification or add additional context in comments.

2 Comments

yeah, it works perfect in jsfiddle. I am using visual studio 2012 and here its not working. I'm happy it worked somewhere else. Still if I could know why its not working in VS2012 it'll be good..
hi, I had added an image, plz hav a look
0

You have not initialized any angular app so far. In your control.js

myApp=angular.module('myApp', []); myApp.controller('myController', function ($scope) { and in your HTML

<body ng-app="myApp"> This should solve it.. :)

7 Comments

Hii, I had seen examples of controllers as functions without modules. Trying that way...
Not sure, where you came across that.. But an angular app is the starting point on any angular application.. there might be scenarios, where ng-app might not be present in the same file e.g. in case of nested views etc. But its a must to have an angular app.. :)
I agree using the ng-app="". I did that too still did not get the result.
you have to name your app.. Did you try the code snippet, I put up earlier??? Is it not working even after that ???
plz have a look on the #1 and #2 methods for creating controllerslink
|

Your Answer

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.