2016-08-05 19 views
-2

我可以做這樣的事情在php 角度js值將分配到PHP值,任何技巧?angularjs的值需要通過在php變量

$phpVariable={{automation.start_flag}}; 
    //echo $phpVariable; 
    <td> <?php echo $phpVariable ?></td> 

想傳遞一個角度JS值PHP變量 誰能幫助我做到這一點?

塊引用

回答

1
$http({method: 'GET',url: '/someUrl'}) 
.success(function (response) { 
    $scope.resp = response 
}, function(response) { 
    console.log(response) 
}); 

HTML

<div>{{resp}}<div> 
-1

AngularJS

angular.module('scopeExample', []).controller('MyController', ['$scope', function($scope) { 
    $scope.username = '<?php echo $phpVariable; ?>' 

    $scope.sayHello = function() { 
    $scope.greeting = 'Hello ' + '<?php echo $phpVariable; ?>' + '!'; 
    }; 
}]); 

HTML

<td> {{username}}</td> 
<td ng-init="sayHello"> {{greeting}}</td> 
+0

基本上我不想PHP價值angularjs,我想角JS值PHP變量 –

+0

角到PHP只異步通訊 –

3

使用Ajax請求:

$http({ 
     url: "YOUR_URL.php", 
     method: "POST", 
     data: { 
      data: variable 
     } 
    }).success(function(response) { 
    console.log(response); 
}); 

對於後端可以得到變量:

<?php 
$your_request = json_decode(file_get_contents('php://input')); 
$your_variable = $your_request->data 
?>