[AngularJS]在 Jquery 函数 angularJS︰ 捕获 TypeError︰ 无法读取属性 'noDisagree' 的定义

发布时间: 2017/4/16 20:47:56
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

嗨我想调用 AngularJs controller 函数中的参数与 Jquery 而得到

未捕获 TypeError︰ 无法读取属性 'noDisagree' 的定义

function noDisagree(id){
  var idToNg = parseInt(id);
  return angular.element('#voteChartsController').scope().noDisagree(idToNg);
} 

任何帮助将不胜感激 !

呆瓜︰ https://plnkr.co/edit/nBvSGh?p=preview

解决方法 1:

我没看到任何地方在您调用 noDisagree 函数。所以,我以为,并为您创建的小提琴︰ https://jsfiddle.net/rumba_alex47/w5vzm4n2/

更新︰http://plnkr.co/edit/GAStnqcVN4I9hFiz32rT?p=preview

最终的解决办法使用 interPolateProvider ,正如你想要:)

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example - example-custom-interpolation-markup-production</title>


  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>



</head>
<body ng-app="customInterpolationApp">
  <script>
  var customInterpolationApp = angular.module('customInterpolationApp', []);

  customInterpolationApp.config(function($interpolateProvider) {
     $interpolateProvider.startSymbol('<%');
  $interpolateProvider.endSymbol('%>');
  });


  customInterpolationApp.controller('DemoController', function($scope) {
    $scope.issues = [{"id":"26","id_issue":"12"},{"id":"26","id_issue":"11"}];
    $scope.noDisagree = function(id_issue) {
      var count = 0;
      for (var i = 0; i < $scope.issues.length; i++) {
        if ($scope.issues[i].id_issue == id_issue) {
            count++;
        }
      }
      return count;
    }
  });
  function noDisagree(id){
  var idToNg = parseInt(id);
  return angular.element('#DemoController').scope().noDisagree(idToNg);
} 

</script>
<div ng-controller="DemoController as demo">
    Here is the issue ID # <% noDisagree(11) %> </div>
</body>
</html>
赞助商