[英]AngularJS expressions not working in <img-crop>
I am trying to modify the project ngImgCrop ( https://github.com/alexk111/ngImgCrop ) for allowing crop multiple images in the same page, but I do not know how many images I would need, this is created dynamically. 我正在尝试修改项目ngImgCrop( https://github.com/alexk111/ngImgCrop ),以允许在同一页面中裁剪多个图像,但是我不知道我需要多少图像,这是动态创建的。 So, I need to associate to the 'image' field of a dynamic value, and at the same time I put this variable in my scope.
因此,我需要关联到动态值的“图像”字段,同时将这个变量放入我的范围。 The problem is that this label is not evaluating the angular code.
问题在于该标签未评估角度代码。
<div class="cropArea" id="{{'person'+person.Id}}">
<img-crop image="{{'person'+person.Id}}" result-image="myCroppedImage"></img-crop>
</div>
Even when they have the same code, when the page is loaded the html code shows: 即使它们具有相同的代码,在加载页面时,html代码也会显示:
<div class="cropArea" id="person12345">
<img-crop image="{{'person'+person.Id}}" result-image="myCroppedImage"></img-crop>
</div>
In my scope since the beginning the variable $scope.person12345 is created, but It is impossible to make the binding without this part. 在我的范围内,从开始就创建了$ scope.person12345变量,但是如果没有这部分,就不可能进行绑定。 What can I do?
我能做什么?
Note: In my init() function I create all the variables: 注意:在我的init()函数中,我创建了所有变量:
angular.forEach(persons, function (person, index) {
$scope['person'+person.Id]='';
});
I actually can see the variable $scope.person12345 when the page is loaded. 我实际上可以在加载页面时看到变量$ scope.person12345。 In any case why does the expression worked for the div and not for the img-crop?
无论如何,为什么该表达式只适用于div而不适用于img-crop?
Please put your expression as a function which will execute in the Controller. 请把您的表达式作为将在Controller中执行的函数。 string(appending string) will return by a function like below.
字符串(附加字符串)将通过如下函数返回。
<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';};
Some how there is no parser available in the directive of image
, that's why you need to give parsed expression via a controller. image
指令中没有可用的解析器的某些原因,这就是为什么您需要通过控制器提供解析的表达式的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.