我正在尝试使用lightGallery jQuery插件(http://sachinchoolur.github.io/lightGallery/index.html)与AngularJS一起使用.
我发现一些答案表明我需要一个指令,所以我创建了以下内容:
.directive('lightGallery', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
jQuery(element).lightGallery();
}
};
})
Run Code Online (Sandbox Code Playgroud)
然后在我看来我这样做:
<ul lightGallery>
<li ng-repeat="photo in album.photos" data-src="{{photo.fullres}}">
<img ng-src="{{photo.thumbnail}}" />
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
(我也试过<ul light-gallery>)当我运行页面时,当我点击任何缩略图时没有任何反应.不过,我可以alert()在链接功能中添加一个,然后显示.
如何让AngularJS与jQuery和这个插件一起玩?
更新:
经过一些调试后,似乎jQuery(element).lightGallery()在模型绑定到视图之前执行.那么接下来的问题是,当一切都被约束而不是之前,我如何获得一个被调用的指令.
我正在尝试使用 rest 框架创建用户,但我可以使用相同的电子邮件创建多个用户,我如何验证已接收的电子邮件?
这是我的序列化程序代码:
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
class UserSerializer(serializers.ModelSerializer):
invoices = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
password = serializers.CharField(write_only=True)
def create(self, validated_data):
user = get_user_model().objects.create(
email=validated_data['email'],
username=validated_data['username']
)
user.set_password(validated_data['password'])
user.save()
return user
class Meta:
model = User
write_only_fields = 'password'
read_only_fields = 'id'
fields = ('id',
'username',
'email',
'password',
'invoices',
)
Run Code Online (Sandbox Code Playgroud)
提前致谢!