duoshuo / airpub

a pure front-end blog engine powered by duoshuo API
http://airpub.io
MIT License
361 stars 41 forks source link

如何在模板中加载自定义的js #26

Closed balthild closed 8 years ago

balthild commented 8 years ago

在模板html中引用或嵌入都不能起作用,只能直接加到index.html中。有没有能避免修改index.html的方式?

balthild commented 8 years ago

详细地说明一下情况… 我准备了9张默认的图片(文件名是数字0-8),当 article.meta.background 有定义时显示定义的图片地址,没有时则按顺序循环显示9张图片。 我的思路是通过一个自增的变量来控制输出图片,但是现在的问题就是模板里面嵌入的js代码不能执行,导致变量无法随着文章主循环的输出而自增。 然后我又考虑用随机数的方式,但是发现ng-src属性中的表达式中无法使用函数。 {{article.meta.background || configs.themePath + "/" + configs.theme + "/img/" + Math.floor(Math.rand()*9) + ".jpg"}} 在没有定义文章背景图时只能输出 themepath/themename/img/.jpg

balthild commented 8 years ago

已解决,自定义了一个 Angular 过滤器。 引入js还是直接改index.html好了… 感觉要在模板里面添加一些额外的逻辑比较困难啊……