This is a simplistic AngularJS Ajax example, I haven't tied in the ASP.NET application. I just wanted to show how AngularJS likes to work with server side information.
AngularJS:
// Angular setup
var app = angular.module('myApp', []);
// AngularJS Controller
app.controller('mainCtrl', ['$scope', 'myService', function ($scope, myService) {
// Initialize scope object
$scope.txt_surveyname = {};
// Call the service to retrieve server data
// currently setup to call as soon as the controller is loaded
myService.getData().then(
// On Promise resolve
function (response) {
// Notice how I am assigning to `data`
// that way I can add debug reponse information to the response array if necessary
$scope.txt_surveyname = response.data;
},
// On promise reject
function () {
// Handle any errors
});
}]);
// Services to handle AJAX requests
app.service('myService', ['$q', '$http', function ($q, $http) {
// return an object
return {
getData: function () {
// Start a promise object
var q = $q.defer();
// Connect to the server to retrieve data
$http.get('path/to/file.php',
// On Success
function (response) {
q.resolve(response);
},
// On Error
function (response) {
q.reject(response);
});
return q.promise();
}
};
}]);
Server Side Response path/to/file.php
:
<?php
$sample = array (
'data' => array (
'Text' => '123'
)
);
echo json_encode($sample);
There are other ways (hacks, if you will) that will allow you to assign data to AngularJS on page load, but the above is the preferred.
There also may be a better way with ASP.NET but I haven't used ASP.NET and AngularJS together yet, other than a little playing around here and there.
Possibly Helpful Links:
https://stackoverflow.com/a/20620956/1134705
AngularJS in ASP.NET
How to use AngularJS in ASP.NET MVC and Entity Framework