drwf69817 2017-02-02 06:12
浏览 192
已采纳

如何在Angularjs中调用函数?

  <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;});    
    function getInfo(){
      $http.post('getTask1.php').success(function(data){
         $scope.details = data;
      })
    }      
  });
</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;});    
    function getInfo(){
      $http.post('getTask2.php').success(function(data){
         $scope.details = data;
      })
    }      
  });
</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;});    
    function getInfo(){
      $http.post('getTask3.php').success(function(data){
         $scope.details = data;
      })
    }      
  });
</script>

I have 3 scripts on 3 different pages with same ng-app and ng-controller.

Below code is my gettask1.php for script1 and similar pages i have created for all scripts to fetch records from diffrent tables. but problem is i can only retrive only last scripts data in all tabs.Im new in angularjs please help me with the same thanks in advance.

<?php
ob_start();
session_start();
include"includes/dbconfig.php";
$org_id=$_SESSION['org_id'];
if(!isset($_SESSION['org_id'])){
header("Location:index.php");
}
getInfo();
$query = "SELECT * from `offer_letter` ORDER BY `offer_id` ASC";
$result = mysql_query($query);
$arr = array();
if(mysql_num_rows($result) != 0) {
while($row = mysql_fetch_assoc($result)) {
$arr[] = $row;
}
}
echo $json_info = json_encode($arr);
?>
  • 写回答

1条回答 默认 最新

  • doujue1246 2017-02-02 07:24
    关注

    You can do this:

         (function(angular) {
            angular.module('controllerExample', [])
              .controller('myctrl', ['$scope', myctrl]);
            function myctrl($scope) {     
    
        $scope.example=function example(){
    
             //your code will be  here 
           }
    
        function example2(){
          //do your code. You can call this function only in this controller.
        }
      example2();
    
        }
    })(window.angular);
    

    You can call example() from your template.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型