繁体   English   中英

jade mixin与动态js对象变量作为属性

[英]jade mixin with dynamic js object variable as attribute

我试着像这样在玉器中调用mixin

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

错误: Unexpected token { at Function (native) at assertExpression ...

我也尝试过这样的:

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

错误: Cannot read property 'project' of undefined

我究竟做错了什么?

更新 :mixin看起来像这样

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

当你使用AngularJS和Jade时,最好使用带有自己模板的指令(如果你想要的话由Jade提供支持)

您正在使用它的情况并不正确,jade将构建为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: '='}
    };
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM