dorpbn1027 2017-02-01 06:36
浏览 185

如何在许多页面上使用ng-app和ng-controller?

I'm stuck in CRUD Operations in AngularJS.

  1. index.html. on this page on body I am using ng-app and ng-controller.
  2. offer_letter_dashboard.php and
  3. termination_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.

  • 写回答

1条回答 默认 最新

  • dsa80833 2017-02-01 06:59
    关注

    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

      var app = angular.module('myApp', []);
      app.controller('myCtrl', function($scope, $http) 
      {
          var getData=function(url){
             $http.get(url)
             .then(function(response){
             $scope.names = $scope.names = response.data.service;});
             getInfo();
             function getInfo(){
             $http.post('gettermination.php').success(function(data)
              {
                $scope.details = data;
              })
            }
          } 
    
      });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog