0

I am new to angular JS and not resolve the error i don't know what is the issue in this code. Error occurred as ReferenceError: Fname is not defined in Angular JS

<body ng-app="login" ng-controller="oput">
    <label>Firstname:</label><input type="text" ng-model="welcome.Fname"><br>
    <label>Lastname:</label><input type="text"  ng-model="welcome.Lname"><br>
    <button ng-click="fun()">Submit</button><br>
    <p>{{welcome.Fname}}</p>

    <script>

        var app=angular.module("login",[]);
        app.controller("oput", function($scope){
        $scope.welcome={Fname:"",
                        Lname:""}

         $scope.fun=function(){
            if(Fname == "raam" && Lname == "Chandru"){
            alert("hi raam");
         }
            else {
                alert("it is incorrect");
            }

        }

});

</script>       
</body>
2
  • Welcome to Stack Overflow. Just to let you know, it's unclear exactly what is going on in the example you give. Please consider editing your question to improve the formatting, and perhaps provide additional context so we can help you solve this. Commented Feb 25, 2016 at 6:08
  • 1
    Fname should be $scope.welcome.Fname Commented Feb 25, 2016 at 6:10

1 Answer 1

2

Try this approach. I've added $scope.welcome.variableName to the if condition.

<body ng-app="login" ng-controller="oput">
    <label>Firstname:</label><input type="text" ng-model="welcome.Fname"><br>
    <label>Lastname:</label><input type="text"  ng-model="welcome.Lname"><br>
    <button ng-click="fun()">Submit</button><br>
    <p>{{welcome.Fname}}</p>

    <script>

        var app=angular.module("login",[]);
        app.controller("oput", function($scope){
        $scope.welcome={Fname:"",
                        Lname:""}

         $scope.fun=function(){
            if($scope.welcome.Fname == "raam" && $scope.welcome.Lname == "Chandru"){
            alert("hi raam");
         }
            else {
                alert("it is incorrect");
            }

        }

});

</script>       
</body>

Here is the DEMO

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

Comments

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.