只有当我在$ timeout

时间:2017-02-14 20:46:01

标签: javascript angularjs http

我在这里遇到问题,每当我点击组件内部的按钮时,我看到我正在进行$ http调用而我在控制台中没有得到响应,但在浏览器中我看到了调用是的。

仅当我取消注释$ timeout函数时才会调用数据。

JS

var app = angular.module('myApp', []);
app.controller('mainCtrl', [$scope, $http, $timeout, function($scope, $http, $timeout) {

   $scope.navigate = function () {
      $scope.getStats();
   }

   $scope.getStats = function () {
      //$timeout(function () {
            $http
                .get('/scripts/controllers/fda/appSvc.json')
                .then(function (response) {
                    console.log(response.data);
                }, function (error) {
                    console.log(error);
                })
     //}, 0)
   };

    $scope.detailedTableCtrl = {
        navigate: $scope.navigate
    }

}]);

app.component("myBox",  {
      bindings: {
            'detailedTableCtrl': '='
        },
      controller: function($element) {

      },
      controllerAs: 'myBox',
      templateUrl: "/template",
      transclude: true
})

HTML

 <div ng-app="myApp" ng-controller="mainCtrl">
      <my-box detailed-table-ctrl="detailedTableCtrl"></my-box>
    </div><!--end app-->

<!--mybox component-->
    <button class="btn btn-default btn-sm" ng-click="myBox.detailedTableCtrl.navigate()">
                <span class="glyphicon glyphicon-chevron-left"></span>
                <span>Back</span>
            </button>

1 个答案:

答案 0 :(得分:0)

正如@Amy指出的那样,我没有看到注入$ http服务。另外请使用服务来使用数据并在控制器中注入服务。您的控制器不应该担心调用/使用数据。

// obtain a raw-pointer c_result through pthread_join as 
// shown above:
let mut c_result = ...;
libc::pthread_join(tid1, &mut c_result as *mut _);

#[repr(C)]
struct ThreadResult { ... } // fields copy-pasted from C

unsafe {
    // convert the raw pointer to a Rust reference, so that we may
    // inspect its contents
    let result = &mut *(c_result as *mut ThreadResult);

    // ... inspect result.field1, etc ...

    // free the memory allocated in the thread
    libc::free(c_result);
    // RESULT is no longer usable
}