User61956409 posted
Hi erum,
i want that when user click on button ..it should display what ever written in text box
In your code, we can find that you use the ng-controller
directive (ng-controller="sampleController"
) to add a controller to your application, but you name the controller with "MyController" in your JavaScript
code, which causes the issue. You can refer to the following code snippet to modify your code.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.2/angular.min.js"></script>
</head>
<body ng-app="sampleApp" ng-controller="sampleController">
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Name
</td>
<td>
<input type="text" ng-model="name" />
<button type="button" ng-click='sayHello()'>greet</button>
</td>
</tr>
</table>
<br />
<br />
{{greeting}}
</div>
</form>
</body>
</html>
<script>
var app = angular.module('sampleApp', []);
app.controller("sampleController", function ($scope, $http) {
$scope.sayHello = function () {
$scope.greeting = 'Hello ' + $scope.name + '!';
};
})
</script>
Test result:

Besides, you are using asp.net webfrom application, please set button type to "button" to prevent submit form.
<button type="button" ng-click='sayHello()'>greet</button>
With Regards,
Fei Han