Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initializing model using a Global function doesn't seem to work for me? #14

Open
darshakmehta opened this issue Feb 8, 2016 · 2 comments

Comments

@darshakmehta
Copy link

What is going wrong here ?

<!doctype html>
<html lang="en" data-ng-app>
<head>
    <meta charset="utf-8">
    <title>AngulasJS Demo3</title>
    <script src ="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
    <script>
        function nameController($scope){
            $scope.firstname = 'John';
            $scope.lastname = 'Smith';
        }
    </script>
</head>
<body data-ng-controller = "nameController">
First Name : <input type = "text" data-ng-model="firstname"></input> 
<br />
<br />
Last Name : <input type = "text" data-ng-model="lastname"></input> 
<br />
<br />
Hello {{ firstname }} {{lastname}}

</body>
</html>

demo

@BrahamMounir
Copy link

Hi, me to I got the same problem it seems that it doesn't work fine !
do we miss something ?

@jainvishal520
Copy link

jainvishal520 commented Mar 8, 2017

@tech-boy You need to initialize angular app and controller like this


<!doctype html>
<html lang="en" data-ng-app='myapp' >
<head>
    <meta charset="utf-8">
    <title>AngulasJS Demo3</title>
    <script src ="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.9/angular.min.js"></script>
    <script>
        angular.module('myapp',[])
          .controller('nameController',nameController);

        function nameController($scope){
            $scope.firstname = 'John';
            $scope.lastname = 'Smith';
        }
    </script>
</head>
<body data-ng-controller = "nameController">
First Name : <input type = "text" data-ng-model="firstname"></input> 
<br />
<br />
Last Name : <input type = "text" data-ng-model="lastname"></input> 
<br />
<br />
Hello {{ firstname }} {{lastname}}

</body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants