When i initialize the $scope.s with some value it's working properly. But when it's not initialize with any value as shown below, it generates error in console saying $scope.s undefined on click event bind with button
var mainApp = angular.module('mainApp', ['ngRoute']);
mainApp.controller('homeCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.title = 'Home page';
$scope.s = '';
$scope.m = '';
$scope.subscribe = function () {
console.log($scope.s); // undefined
}
}]);
<div data-ng-app="mainApp" data-ng-controller="homeCtrl">
<div>
<h1>{{title}}</h1>
</div>
<div>
<h3>Want to become a seller and earn more..?</h3>
<p>Add your email and we will get in touch.</p>
<div>
<input type="email" data-ng-model="s" id="txtEmail" />
</div>
<div>
<div>
<button data-ng-click="subscribe();">Send</button>
</div>
</div>
</div>
<div>
{{m}}
</div>