【问题标题】:Not able to use eval() with angular无法将 eval() 与 angular 一起使用
【发布时间】:2016-03-24 12:39:56
【问题描述】:

我正在尝试使用 javascript 中的 eval 来调用 angular.js 中的函数。我在字符串中有它的名字

我使用了以下内容:

$scope.$eval("$scope.drawFactory.draw")({},$scope.paint); 

但它正在显示

TypeError: $scope.$eval(...) is not a function

这样做的正确方法是什么?

【问题讨论】:

标签: javascript angularjs angularjs-scope eval


【解决方案1】:

您可以将expression(string)/function 传递给$eval,这将针对控制器范围进行评估。 $eval 字符串无需使用$scope

$scope.$eval("drawFactory.draw")

你在哪里做$eval函数&再次调用该函数调用

//below is obviously gonna throw an error
$scope.$eval("$scope.drawFactory.draw")({},$scope.paint); //incorrect function execution

【讨论】:

    猜你喜欢
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-11
    • 2019-07-15
    相关资源
    最近更新 更多