-1

angularjs 1.2.0 $http 不在 $eval 中发送请求

代码 http://jsbin.com/oZUFeFI/3/watch?html,js,输出

4

1 回答 1

0

我切换到非缩小的 AngularJS 并放入一些断点以查看 $http 的哪些部分正在命中,并且由于某种原因未调用 sendReq 方法。没有完全缩小范围,但添加 $timeout 似乎可以解决它:

http://jsbin.com/iZihebI/3/edit

var myApp = angular.module('myApp', ['ng']);

myApp.controller('test', function($scope, $http, $timeout) {
  $scope.get = function(search) {
    console.log(search);
    $timeout(function(){$http.get('http://jsbin.com/')},1);
  };
}).directive('xxx', function() {
  return {
    restrict: 'A',
    link: function(scope, elem, attr) {
      var searchScope = scope.$new();
      searchScope.$search = 'search text ...';
      elem.bind('click', function(e) {
        searchScope.$eval(attr.c);
      });
    }
  };
});
于 2013-09-03T04:19:25.620 回答