2

That's my complete code angular is not printing vars in the body tag of the html pice, console.log() everywhere is working. ng-click at submit button is also working.

<html ng-app="fb">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap      /3.3.7/css/bootstrap.min.css"
 integrity="sha384-   BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" 
crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5  /angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-cookie/4.1.0/angular-cookie.js"></script>

<script>
var app=angular.module('fb', []);

app.controller('home',function($scope){
    var hi;
    $scope.hi=5;
    //$rootScope.hola=9;
    console.log($scope.hi);
    //console.log($rootScope.hola);

    $scope.submitSignup=function()
    {
    var hi;
    $scope.hi=5;
    //$rootScope.hola=9;
    console.log($scope.hi);
    //console.log($rootScope.hola);
    console.log($scope.username);
        alert('button pressed');
    };
});

</script>
<head>
<title>Index</title
</head>

<body>
<div ng-controller='home'>
<input type="text" placeholder="Username" ng-model="username">
<br>
<input type="password" placeholder="Password" ng-model="password">
<br>

<button type="button" ng-click="submitSignup()">SignUp</button>

<br>

<p> {{username}} </p>


<p> {{hi}} </p>


{{hola}}


</div>

<p> index </p>
</body>
</html>

Scratching my head for hours and hours at this, any help will be appreciated.

2 Answers 2

2

add ng-app in your template with ng-app="fb"

DEMO

 
<html ng-app="fb">
<head>
<title>Index</title>
</head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.min.js"></script>
<script>
var app=angular.module('fb', []);
app.controller('home',function($scope){
    var hi;
    $scope.hi=5;
    //$rootScope.hola=9;
    console.log($scope.hi);
    //console.log($rootScope.hola);

    $scope.submitSignup=function()
    {
    var hi;
    $scope.hi=5;
    //$rootScope.hola=9;
    console.log($scope.hi);
    //console.log($rootScope.hola);
    console.log($scope.username);
        alert('button pressed');
    };
});
</script>
<body>
<div ng-controller='home'>
<input type="text" placeholder="Username" ng-model="username">
<br>
<input type="password" placeholder="Password" ng-model="password">
<br>
<button type="button" ng-click="submitSignup()">SignUp</button>
<br>
<p> {{username}} </p>
<p> {{hi}} </p>
{{hola}}
</div>
<p> index </p>
</body>
</html>

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

6 Comments

ng-app="fb" is added above all sources in the <html> tag.
did you check the demo? in your html there is no reference for angular and script
These are the links I have added, ng-click works so angular does work. <link rel="stylesheet" href="maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <script src="ajax.googleapis.com/ajax/libs/angularjs/1.6.5/…> <script src="ajax.googleapis.com/ajax/libs/angularjs/1.6.4/…> <script src="cdnjs.cloudflare.com/ajax/libs/angular-cookie/4.1.0/…>
where is the reference for your controller and module script
they are in the same file so maybe no reference needed?
|
1

You forgot to initiate your app with ng-app="fb"

 <body ng-app="fb">
    <div ng-controller="home">
        <input type="text" placeholder="Username" ng-model="username">
        <br>
        <input type="password" placeholder="Password" ng-model="password">
        <br>
        <button type="button" ng-click="submitSignup()">SignUp</button>

        <p> {{username}} </p>

        <p> {{hi}} </p>

        {{hola}}

    </div>
    <p> index </p>
</body>

</html>

8 Comments

ng-app="fb" is added above all sources in the <html> tag.
Show your files which are loaded in ur above html
These are the links I had from angular's documentation. Angular is working, but data is not being displayed also ng-click does calls my function and generates alert.
Try to abstract your angular code into a js and give the reference to that js file in your above html
that space was added maybe while posting, its not in my source code. Okay going to put it in js file. But it should work this way.
|

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.