I was learning angular2, Now I have one doubt. How to use PHP in Angular 2? Because Angular 2 files are .html type. So how to use it?
2 Answers
The HTML files would call PHP API(.php files), to get response and display accordingly.
For example:
<script>
var countryApp = angular.module('countryApp', []);
countryApp.controller('CountryCtrl', function ($scope, $http){
$http.get('country.php').success(function(data) {
$scope.countries = data;
});
});
</script>
1 Comment
andrea06590
Not necessary + it's angularJs
You should think differently, what should I use as front end & back end ? Angular works with webservices and API. So in most cases, you'll need to build an API. I would suggest you ExpressJS & Node or even an ElasticSearch Database to first understand APIs.
Useful link : https://www.codeofaninja.com/2017/02/create-simple-rest-api-in-php.html