4

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?

V31
  • 7,626
  • 3
  • 26
  • 44
  • I think there is no need to use mixins in angularjs projects. Can you show us your code? We'll try to find alternative solution for you – karaxuna Aug 30 '13 at 07:10
  • Thanks for the response. The problem is solved. Used element directives and passed in the template which was earlier written in mixins. – V31 Aug 30 '13 at 10:25

2 Answers2

3

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 :)

Tarion
  • 16,283
  • 13
  • 71
  • 107
  • Note: in this example, the mixin must expect to receive an argument called `avatar` which will contain the object that is passed to it. `mixin avatarRow(avatar)` – Jeremy Moritz Jul 23 '15 at 14:30
0

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.

V31
  • 7,626
  • 3
  • 26
  • 44