Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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表达式不适用于<;img作物>;_Angularjs_Ng Img Crop - Fatal编程技术网

AngularJS表达式不适用于<;img作物>;

AngularJS表达式不适用于<;img作物>;,angularjs,ng-img-crop,Angularjs,Ng Img Crop,我正在尝试修改ngImgCrop()项目,以允许在同一页面中裁剪多个图像,但我不知道需要多少图像,这是动态创建的。因此,我需要关联到一个动态值的“image”字段,同时我把这个变量放在我的范围内。问题是该标签没有计算角度代码 <div class="cropArea" id="{{'person'+person.Id}}"> <img-crop image="{{'person'+person.Id}}" result-image="myCroppedImage">

我正在尝试修改ngImgCrop()项目,以允许在同一页面中裁剪多个图像,但我不知道需要多少图像,这是动态创建的。因此,我需要关联到一个动态值的“image”字段,同时我把这个变量放在我的范围内。问题是该标签没有计算角度代码

<div class="cropArea" id="{{'person'+person.Id}}">
    <img-crop image="{{'person'+person.Id}}" result-image="myCroppedImage"></img-crop>
</div>

在加载页面时,我实际上可以看到变量$scope.person12345。在任何情况下,为什么表达式适用于div而不适用于img裁剪?

请将表达式作为函数,在控制器中执行。字符串(追加字符串)将由如下函数返回

    <div class="cropArea" id="{{'person'+person.Id}}">
        <img-crop image="getImagePath(person.Id)" result-image="myCroppedImage"></img-crop>
    </div>

Controller like below:

    $scope.getImagePath = function(id){return 'person'+id+'.png';};

控制器如下所示:
$scope.getImagePath=function(id){return'person'+id+'.png';};

在指令
image
中没有可用的解析器,这就是为什么需要通过控制器给出解析表达式。

根据文档,image应该是一个可分配的角度表达式。给我们看看你的控制器代码。假设您有一个人员数组,而不是定义$scope.person12345,请定义
$scope.persons[i].image
,并在重复迭代人员时使用
image=“person.image”
。编辑问题中的所有相关代码。不是在那些无法阅读的评论中。我做到了。但即使当我看到它进入函数并返回正确的值时,当我调试时,最终html是:
我没有放入.png,因为这不是图像的路径,它是绑定到此的作用域变量的名称。请尝试返回已形成变量的值<代码>$scope.getImagePath=函数(id){return$scope['person'+id];}
angular.forEach(persons, function (person, index) {        
    $scope['person'+person.Id]=''; 
}); 
    <div class="cropArea" id="{{'person'+person.Id}}">
        <img-crop image="getImagePath(person.Id)" result-image="myCroppedImage"></img-crop>
    </div>

Controller like below:

    $scope.getImagePath = function(id){return 'person'+id+'.png';};