Use Angular js API with ASP.net Web Filters

I am using angular js with Asp.net web forms. I want to get data from a database using the angular js API. Everything I've seen on Google or any tutorial uses the angular js API with Asp.net MVC.

My question is: can we use the angular js API with Asp.net web forms?

If so, will the method be the same as in Asp.net MVC?

Further, I know that angular js is for SPA (single-page application), and it has views and model controllers.

+6
source share
2 answers

Yes you could.

But I really really do not recommend it. It can be extremely difficult to guarantee that they don't step over each other's fingers, because they both work to improve HTML.

My recommendation is that you start moving your business logic from the web form code behind to the Service classes so that you can expose the business logic using [WebMethods]. You can add WebMethods to the pages , but it would be better if you could add the endpoint of the REST web service using the WebAPI.

Think of angular SPA as completely independent of server technology, all you need for angular to work with the server is the HTTP API, preferably the one that returns JSON.

+8
source

Hi, you can use angular with web forms, and you can make a one-page application also using the $ HTTP service in angular. I wrote one ajax call using a web form.

<script type="text/javascript" ><src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script> <script type="text/javascript"> var app = angular.module('MyApp', []) app.controller('MyController', function ($scope, $http, $window) { $scope.ButtonClick = function () { var post = $http({ method: "POST", url: "Default.aspx/GetCurrentTime", dataType: 'json', data: { name: $scope.Name }, headers: { "Content-Type": "application/json" } }); post.success(function (data, status) { $window.alert(data.d); }); post.error(function (data, status) { $window.alert(data.Message); }); } }); </script> <div ng-app="MyApp" ng-controller="MyController"> Name: <input type="text" ng-model="Name" /> <br /> <br /> <input type="button" value="Submit" ng-click="ButtonClick()" /> </div> 
0
source

Source: https://habr.com/ru/post/977264/


All Articles