2017-02-02 5 views
-1
<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> 

同じng-appとng-controllerを使用して、3つの異なるページに3つのスクリプトがあります。Angularjsで関数を呼び出す方法は?

以下のコードは、script1のための私のgettask1.phpと、私が異なるテーブルからレコードをフェッチするために作成した同様のページです。しかし問題は、すべてのタブの最後のスクリプトデータのみを検索することができるということです.Imartで新しいことは、前もって同じ感謝の助けを借りてください。

<?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); 
?> 

答えて

0

あなたはこれを行うことができます。

 (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); 

あなたのテンプレートから一例を()を呼び出すことができます。

関連する問題