小编Dav*_*veJ的帖子

是否可以在AngularJS模板中执行可重用的片段?

我发现自己一次又一次地重复相同的代码片段,是否有可能在AngularJS中做这样的事情:

<div ng-snippet="mySnippet"> 
  This is a snippet 
</div> 

<div ng-snippet="anotherSnippet"> 
  Yet another snippet!!
</div>

<ng:include src="anotherSnippet">
<ng:include src="anotherSnippet">
<ng:include src="mySnippet">
Run Code Online (Sandbox Code Playgroud)

而上述的输出将是:

Yet another snippet!!
Yet another snippet!!
This is a snippet
Run Code Online (Sandbox Code Playgroud)

我不一定在寻找这种确切的"ng:include"解决方案或模式,但可以减少模板中的重复.

javascript angularjs

27
推荐指数
2
解决办法
1万
查看次数

对表格行使用ng-repeat

我正在尝试将模型中的数据插入到模板中,但我想在每7次重复后添加一个新的表行.使用基于strign的模板,我可以使用迭代索引和模数很容易地完成它,但我无法弄清楚如何使用angular的DOM模板来做到这一点.

这是HTML:

<div ng-controller="MyCtrl">
  <table cellspacing="0" cellpadding="0">
   <colgroup span="7"></colgroup>

   <tbody>
     <tr class="days">
       <th scope="col" title="Monday">Mon</th>
       <th scope="col" title="Tuesday">Tue</th>
       <th scope="col" title="Wednesday">Wed</th>
       <th scope="col" title="Thursday">Thu</th>
       <th scope="col" title="Friday">Fri</th>
       <th scope="col" title="Saturday">Sat</th>
       <th scope="col" title="Sunday">Sun</th>
     </tr>
     <tr>
         <td ng-repeat="date in dates">
             {{ date }}
             <!-- After seven iterations a new `<tr>` should be aded -->
        </td>
     </tr>
 </tbody>
 </table>
</div>
Run Code Online (Sandbox Code Playgroud)

和它的javascript类似:

myApp = this.angular.module('myApp', []);

var monthDays = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, …
Run Code Online (Sandbox Code Playgroud)

angularjs

24
推荐指数
3
解决办法
9万
查看次数

使用Firebase和Electron

我正在尝试使用Firebase和Electron.当我在网页上安装它时,它不起作用,因为Electron页面是本地托管的,没有hostname.这是我得到的错误......

Uncaught Error: This domain is not authorized for OAuth operations for your Firebase project. Edit the list of authorized domains from the Firebase console.
Run Code Online (Sandbox Code Playgroud)

我无法将空(或通配符)授权域添加到Firebase控制台,因此我卡住了.有没有人对如何解决这个问题有任何想法?

编辑:这是我正在使用的代码,它只是标准的样板,没有什么额外的......

<script src="https://www.gstatic.com/firebasejs/live/3.0/firebase.js"></script>
<script>
  var config = {
    apiKey: "AIzaSyBvmmPB0_Oddc-02cUj3Ntt3wi8jSxxxx",
    authDomain: "xxxxx-d24ad.firebaseapp.com",
    databaseURL: "https://xxxxx-d24ad.firebaseio.com",
    storageBucket: "",
  };
  firebase.initializeApp(config);
</script>
Run Code Online (Sandbox Code Playgroud)

html javascript firebase electron

14
推荐指数
2
解决办法
1万
查看次数

从jqGrid中检索原始行数据

可以使用getRowData方法来检索单元格的当前内容,但这会在它通过格式化程序之前检索当前单元格内容而不是原始数据.

如何在应用格式转换之前检索原始内容?仅供参考我使用JSON填充表格.

javascript jquery json jqgrid

11
推荐指数
1
解决办法
3万
查看次数

Grunt手表任务似乎需要很长时间

我正在运行两个运行时间<100毫秒的简单任务,但是当在watch命令下运行时,两个组合任务总共需要大约8秒(每个任务的开销似乎为3.5秒).我正在使用它进行实时重载以进行开发,我发现它非常令人沮丧.我尝试过设置spawn,false但这似乎打破了它,并没有运行任何相关的任务.

这是更改sass文件时的示例输出.

>> File "app/styles/main.scss" changed.

File "app/styles/main.css" created.

Done, without errors.

Elapsed time
loading tasks   4ms  ????? 9%
sass            1ms  ?? 2%
sass:dist      39ms  ?????????????????????????????????????????? 89%
Total 44ms
Completed in 3.862s at Mon Nov 18 2013 17:05:57 GMT+0000 (GMT) - Waiting...
OK
>> File "app/styles/main.css" changed.

Running "copy:styles" (copy) task
Copied 1 files

Done, without errors.

Elapsed time
loading tasks   4ms  ???????????? 24%
copy:styles    13ms  ???????????????????????????????????? 76%
Total 17ms
Completed in 3.704s at Mon Nov …
Run Code Online (Sandbox Code Playgroud)

node.js gruntjs yeoman grunt-contrib-watch

9
推荐指数
1
解决办法
5461
查看次数

在Webpack中读取已解析路径的文件

我有一个节点模块,我想让它与webpack兼容.我目前正在使用以下模式:

const fs = require('fs');
const someTemplate = require.resolve('./templates/template.css');

fs.readFile(someTemplate, 'utf8', (err, templateStr) => {
  // Do something with`templateStr`
});
Run Code Online (Sandbox Code Playgroud)

问题是require.resolve将返回模块ID(数字)而不是路径,当然对数字执行readFile操作将失败.

如何使它与node和Webpack兼容.

javascript node.js webpack babeljs

5
推荐指数
1
解决办法
6111
查看次数

Prettier + eslint 换行符

我将 eslint 与 VSCode 1.18.1 和更漂亮/更漂亮的扩展 0.26.0 用于 VSCode。在我的 VSCode 配置中,我有"prettier.eslintIntegration": true,. 我的依赖项曾经是:

"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.1.3",
"eslint-plugin-import": "^2.2.0",
Run Code Online (Sandbox Code Playgroud)

通常 prettier-eslint 格式如下:

return somePromise.then(result =>
  someOtherPromise(result, { foo: 'bar' })
);
Run Code Online (Sandbox Code Playgroud)

然后我升级到:

"eslint": "^4.11.0",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-plugin-import": "^2.8.0",
Run Code Online (Sandbox Code Playgroud)

现在 prettier-eslint 正在格式化文件,而不是这样:

return somePromise.then(result =>
  someOtherPromise(result, { foo: 'bar' }));
Run Code Online (Sandbox Code Playgroud)

这是一个微不足道的例子,但如果缩进深几级,那么它就会变得难以阅读。我更喜欢旧风格。

是否可以通过升级的依赖项实现以前的格式样式?

eslint visual-studio-code eslint-config-airbnb prettier jsprettier

4
推荐指数
1
解决办法
7599
查看次数