Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI All,

I am not so sure if I can ask an angular based question on this website, if I can't, then please I do apologise.

I have created to textboxes on my HTML form that take the users inputs. With a click of a button I would the text in these textboxes to write to console or in an alert message i don't care as long as the this information displays.

HTML CODE:

XML
<body>


    <div id='content' ng-app='MyApp' ng-controller='MainController'>
        <label>F name:</label>
        <input type="text" ng-model="FirstName"/> <br/>
        <label>L Name::</label>
      &nbsp;  <input type="text" ng-model="LastName"/>
     &nbsp; &nbsp;  <button ng-click="addNew()">Add New</button>


    </div>

</body>



Main JS FILE:

PHP
app.controller("MainController", function($scope) {

    $scope.FirstName = "";
    $scope.LastName = "";


    $scope.addNew = function() {

        console.log(FirstName);
        console.log(LastName);


    };




});



When I click the button nothing happens.. Is there anything I am missing??

Thank you
Posted

1 solution

JavaScript
$scope.addNew = function() {
    // Include $scope. when accessing variables in the scope.
    console.log($scope.FirstName);
    console.log($scope.LastName);
    };
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900