简体   繁体   English

改变参数PHP的可能性? 从控制器

[英]possibility to change a parameter php? from the controller

Is there a possibility to change a parameter params: {source:$scope.chartr1} from the controller - I would like to call a php file with variable parameters. 是否有可能从控制器更改参数参数:{source:$ scope.chartr1} -我想使用可变参数调用php文件。

app.controller('Ctrl', function ($scope, $http) {
$scope.chartr1 = "2010-01-01";
var request = $http.get('xxx.php', {
    params: {source:$scope.chartr1}
 }).success(function(gl){
    $scope.users = gl;    
$scope.chartData = [['Gl', $scope.users]
];
 });

The problem is you are calling $http with the default parameter as soon as the controller runs. 问题是,控制器运行后,您正在使用默认参数调用$ http。 You should write the $http part in a function and call it only when the user is ready (ie after changing the input). 您应该在函数中编写$ http部分,并仅在用户准备就绪时(即更改输入后)调用它。

$scope.request = function() {
  $http.get('xxx.php', {params: source:$scope.chartr1})...
}

<input ng-model="chartr1">
<button type="button" ng-click="request()">submit</button> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM