Qua*_*ent 4 angularjs angularjs-directive
我有一个页面,显示一堆使用 http 检索的图像的缩略图。我使用 ng-repeat 来遍历数组并生成 html。
这很好用。
我还创建了一个自定义指令,将其作为属性绑定到 ng-repeat 生成的 img 元素。
这也很好用。
但是,当我尝试将数据传递到自定义指令的范围时,一切都会崩溃。数据绑定失败,ng-repeat 不会替换图像的 url,因此我最终得到 404,因为 url 无效。目前为止就差不多了。
非常感谢任何帮助,因为我对 Angular 完全陌生。
我的 HTML 模板:
<div class="portfolioContent">
<div class="row">
<div class="col-lg-3 col-md-4 col-sm-4 col-xs-6 col-padding" ng-repeat="gImg in gPhotos">
<div class="photoframe">
<img src="{{gImg.thumbnailUrl}}" url="{{gImg.imageUrl}}" image-gallery>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
和我的自定义指令:
myApp.directive('imageGallery',function(){
return {
restrict: 'A',
scope: {
url: '='
},
controller: function($scope){
console.log($scope.url);
}
}
Run Code Online (Sandbox Code Playgroud)
});
尝试改变
scope: {
url: '='
},
Run Code Online (Sandbox Code Playgroud)
到
scope: {
url: '@'
},
Run Code Online (Sandbox Code Playgroud)
请参阅此处的一个非常简单的示例。检查控制台。看看这里=和之间有什么区别@。
| 归档时间: |
|
| 查看次数: |
10692 次 |
| 最近记录: |