简体   繁体   English

使用自定义属性和模板创建角度指令

[英]Creating angular Directive with custom attributes and template

i'm having some problems with a custom directive to display some images instead of a dropdown. 我在使用自定义指令显示一些图像而不是下拉菜单时遇到一些问题。 but by now i'm stuck with displaying the correct html from my template function. 但是到现在为止,我仍然无法通过模板功能显示正确的html。 Writing the image path directly into my template generates attributes for every part between slashes. 将图像路径直接写入我的模板会为斜线之间的每个部分生成属性。 Eg: 例如:

'src="/path/to/image.jpg"'

is changed to 更改为

src=" path"="" to="" "image.jpg"=""

i even tried to puth those paths in my model but this is the result: https://plnkr.co/edit/EGm5nk?p=preview 我什至试图把那些路径放到我的模型中,但这就是结果: https ://plnkr.co/edit/EGm5nk?p=preview

i found a working example but cannot find the difference: http://plnkr.co/edit/nQbrSi?p=info 我找到了一个有效的示例,但找不到区别: http : //plnkr.co/edit/nQbrSi?p=info

my additional question to this: how do i address a list correctly in my directive? 我对此的另一个问题:如何在指令中正确处理列表?

EDIT: That error was so stupid and easy to oversee 编辑:该错误是如此愚蠢,易于监督

You just missed to close the class inside directive. 您只是错过了关闭类内部指令的机会。 Change 更改

var html = '<div class="foobar">'+
'                    <div class="row"> '+
'                        <div class="col-xs-3 ng-repeat="'+ attrs.ttOptions + '"><img ng-src="{{item.path}}" /></div> '+
'                    </div> '+
'                </div>';
            return html;

to

.....<div class="col-xs-3" ng-repeat="'+ attrs.ttOptions ..... .....<div class="col-xs-3" ng-repeat="'+ attrs.ttOptions .....

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

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