2016-06-23 39 views
1

我想打电话给一个mixin在玉像这样玉混入动态JS对象变量属性

+projectInfo("assets/images/image.jpg",{{repository.project[projectId].unit}}) 

error: Unexpected token { at Function (native) at assertExpression ...

我自己也尝试这样的:

+projectInfo("assets/images/image.jpg",repository.project[projectId].unit) 

error: Cannot read property 'project' of undefined

我究竟做错了什么?

更新:混入看起来像这样

mixin projectInfo(img, title) 
    .container-fluid 
     .col-xs-12.projectInfo 
      .col-xs-12.img 
       img(src= img) 
      .col-xs-12.title 
       h1= title 
+0

嗨,你能不能请帖也mixin的定义? – rick

+0

@rick无法看到这将如何帮助,但上面添加 – suMi

+0

了解参数neede也许??? – rick

回答

0

当您使用AngularJS与翡翠,最好使用指令与自己的模板(搭载玉,如果你想为好)

的你使用它的情况并不是真的,玉将被构建为html,并且在那个过程中,传递给mixin的值将被用于绘制mixin模板而不是+mixinName(),并且由于您想要在其中使用动态值,因此必须使用AngularJs方法:

angular.module('app.directives').directive('projectInfo', projectInfo); 

function projectInfo() { 
    return { 
     restrict: 'AE', 

     //build from jade template and contain {{info.title}}, {{info.img}} 
     templateUrl: '/templates/myTemplate.html', 

     scope: {info: '='} 
    }; 
}