php - How to use ng-app and ng-controller for many pages?
680
I'm stuck in CRUD Operations in AngularJS.
index.html
. on this page on body I am usingng-app
andng-controller
.offer_letter_dashboard.php
andtermination_dashboard.php
on this page I am writing script for adding and fetching data.
I am using the same script on both the pages for fetching data. Here is the script:
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http){
$http.get("http://www.adhr.adnacgroup.com/ADHRM/companyJson.php")
.then(function(response){
$scope.names = $scope.names = response.data.service;
});
getInfo();
function getInfo(){
$http.post('gettermination.php').success(function(data){
$scope.details = data;
})
}
});
</script>
Right now only the first page can retrieve data. Only the first page's script is working fine. And it applies for termination's page too.
Answer
Solution:
You can have multiple instances of the same controller on different pages with ng-app and ng-controller. If you have multiple controllers in the same app, you can use ng-route or ui-router to link the pages If you want to use the same script to make requests to multiple urls you can use a function in your script passing the url