Jade Mixins in AngularJS

对着背影说爱祢 提交于 2020-01-14 13:03:42

问题


Hi I would like to implement Jade templates in my AngularJS project, and have mixin in my template (reusable code).

However the problem that I am facing is that we cannot use Mixin with arguments. Am I doing it correctly or is there any alternative for the same in AngularJS that I am missing?


回答1:


You can create an js object from your model and pass it as strings to the mixin like the following:

+avatarRow({name: '{{avatar.name}}', uuid: '{{avatar.uuid}}', verificationCode: '{{avatar.verificationCode}}', status: '{{avatar.status}}'})

Inside the mixin you can now access e.g. #{avatar.uuid}

I considder to automate this further, because this leads to a duplication of the models code which is not so nice yet. I will share my solution if I get one :)




回答2:


I figured out that mixins cannot be used in Angular as the scope is to be defined. Hence now created element directive and passed in the template (which was meant to be written in Mixin) as the templateUrl in it.



来源:https://stackoverflow.com/questions/18507062/jade-mixins-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!