Reputation: 181
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>
Upvotes: 0
Views: 775
Reputation: 2156
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
Upvotes: 2