使用 ng-repeat 时 Jdenticon 图标不呈现
Jdenticon icons not rendering when using ng-repeat
我一直在为我的用户图标使用 Jdenticon JavaScript 库 (https://jdenticon.com/)。它应该采用散列并将其呈现为 SVG 或 Canvas 使用这样的东西:
<svg width="200" height="200" data-jdenticon-hash="ff8adece0631821959f443c9d956fc39">
Fallback text for browsers not supporting inline svg
</svg>
所以问题是我正在尝试使用 angular ng-repeat 在单个页面上呈现多个用户图标,并在 data-jdenticon-hash 中绑定哈希。看起来所有数据都在它应该在的地方,但 Jdenticon 抱怨它没有看到绑定的数据。如果我在 data-jdenticon-hash 中添加静态散列,比如 "ff8adece0631821959f443c9d956fc39",它会呈现相同但正确的所有图标。
这是我当前的代码:
<div ng-repeat="i in friends" last-element-directive>
<div id="requests" class="col col-md-12 col-sm-12 col-xs-12 tab-pane fade in active" ng-show="user_friends">
<div id="icon" class="col-md-12">
<div class="col-md-1 col-sm-1 col-xs-4">
<svg width="40" height="40" data-jdenticon-hash="{{i.avatar}}"></svg>
</div>
<div class="col-md-3 col-sm-2 col-xs-3">
<h3><a href="/user/?id={{i.username}}" target="_blank">{{i.username}}</a></h3>
</div>
</div>
</div>
</div>
如有任何帮助,我们将不胜感激!
我不是 jdention 方面的专家,只是在为我的项目实施它时偶然发现了这一点。也许对你有帮助:
The problem is that jdenticon.update
is never called for canvases created dynamically as by Angular. A solution could be to create a directive that is responsible for calling jdenticon.update
when the canvas element is constructed.
See this fiddle for an example:
https://jsfiddle.net/w5h6msvd/
来源是这个github问题:https://github.com/dmester/jdenticon/issues/10
编辑:这就是我现在在我的项目中使用它的方式
import identiconImpl from 'jdenticon';
export default () => ({
restrict: 'A',
link: (scope, elem) => {
identiconImpl.update(elem[0], scope.hashValue);
},
scope: {
hashValue: '<'
}
});
这是模板:
<svg identicon hash-value="ctrl.hashAndSaltOperatorName()"></svg>
哦,这里 index.js 包含所有必要的部分:
export default angular
.module('jdenticonHash', [])
.directive('identicon', identiconDirective);
我一直在为我的用户图标使用 Jdenticon JavaScript 库 (https://jdenticon.com/)。它应该采用散列并将其呈现为 SVG 或 Canvas 使用这样的东西:
<svg width="200" height="200" data-jdenticon-hash="ff8adece0631821959f443c9d956fc39">
Fallback text for browsers not supporting inline svg
</svg>
所以问题是我正在尝试使用 angular ng-repeat 在单个页面上呈现多个用户图标,并在 data-jdenticon-hash 中绑定哈希。看起来所有数据都在它应该在的地方,但 Jdenticon 抱怨它没有看到绑定的数据。如果我在 data-jdenticon-hash 中添加静态散列,比如 "ff8adece0631821959f443c9d956fc39",它会呈现相同但正确的所有图标。
这是我当前的代码:
<div ng-repeat="i in friends" last-element-directive>
<div id="requests" class="col col-md-12 col-sm-12 col-xs-12 tab-pane fade in active" ng-show="user_friends">
<div id="icon" class="col-md-12">
<div class="col-md-1 col-sm-1 col-xs-4">
<svg width="40" height="40" data-jdenticon-hash="{{i.avatar}}"></svg>
</div>
<div class="col-md-3 col-sm-2 col-xs-3">
<h3><a href="/user/?id={{i.username}}" target="_blank">{{i.username}}</a></h3>
</div>
</div>
</div>
</div>
如有任何帮助,我们将不胜感激!
我不是 jdention 方面的专家,只是在为我的项目实施它时偶然发现了这一点。也许对你有帮助:
The problem is that
jdenticon.update
is never called for canvases created dynamically as by Angular. A solution could be to create a directive that is responsible for callingjdenticon.update
when the canvas element is constructed. See this fiddle for an example: https://jsfiddle.net/w5h6msvd/
来源是这个github问题:https://github.com/dmester/jdenticon/issues/10
编辑:这就是我现在在我的项目中使用它的方式
import identiconImpl from 'jdenticon';
export default () => ({
restrict: 'A',
link: (scope, elem) => {
identiconImpl.update(elem[0], scope.hashValue);
},
scope: {
hashValue: '<'
}
});
这是模板:
<svg identicon hash-value="ctrl.hashAndSaltOperatorName()"></svg>
哦,这里 index.js 包含所有必要的部分:
export default angular
.module('jdenticonHash', [])
.directive('identicon', identiconDirective);