Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
调用AngularJS javascript函数时语法正确_Javascript_Angularjs - Fatal编程技术网

调用AngularJS javascript函数时语法正确

调用AngularJS javascript函数时语法正确,javascript,angularjs,Javascript,Angularjs,我在下面定义的AngularJS文件中有一个JS函数,我正在调用它 在JS文件中调用此函数时,正确的语法是什么,因为我需要在网格上进行硬刷新 作用 调用函数 您应该考虑使用GealDIDATA提供一个服务功能,它使用角度的内部$HTTP服务返回一个承诺。这种模式的好处是允许您在应用程序和应用程序中的其他位置重用ajax请求 承诺将通过解析其内部ajax调用来解决,因此您将在控制器中调用工厂函数,不要忘记将其作为依赖项注入!与 SearchService.getGridData(url, valu

我在下面定义的AngularJS文件中有一个JS函数,我正在调用它

在JS文件中调用此函数时,正确的语法是什么,因为我需要在网格上进行硬刷新

作用 调用函数

您应该考虑使用GealDIDATA提供一个服务功能,它使用角度的内部$HTTP服务返回一个承诺。这种模式的好处是允许您在应用程序和应用程序中的其他位置重用ajax请求

承诺将通过解析其内部ajax调用来解决,因此您将在控制器中调用工厂函数,不要忘记将其作为依赖项注入!与

SearchService.getGridData(url, valueObject).then(function(result) {
    //you will have access to the result of the Ajax call inside this callback function only.
    //Be sure to bind it for use in other places in your application!
    console.log(result);
})
相关内容如下:


viewModel是控制器的对象吗?是的,它是一个对象。Bergi,网格不会被刷新。当我检查函数调用中变量的值时,它们是未定义的。这里没有足够的内容来解释您的问题是什么。你的问题是什么是正确的语法…,但你的实际问题似乎是为什么你在其他地方得到了一个未定义的值,在一些你甚至没有发布在这里的代码或HTML中。请考虑将问题和实际问题稍微多加一点,包括A。此外,为什么要使用$HTTPPOST来表示应该是GET操作的东西?
viewModel.getGridData(ajaxUrl, searchValues);
myApp.factory('SearchService', function($http) {
    return {
      getGridData: function(url, valueObj) {
        return $http.post(url, valueObj);
      }
    }
});
SearchService.getGridData(url, valueObject).then(function(result) {
    //you will have access to the result of the Ajax call inside this callback function only.
    //Be sure to bind it for use in other places in your application!
    console.log(result);
})