小编Jbi*_*ird的帖子

Cordova使用Typescript插入Ionic 1应用程序

我是Typescript的新手.我刚刚使用Typescript开始了一个Ionic 1.2.4(Angular)项目.转换时,Property 'Keyboard' does not exist on type 'CordovaPlugins'由于传递给angular.module.run()文件中的以下函数,我收到错误消息run.ts

///<reference path="../../typings/tsd.d.ts"/>

export function onRun($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if (window.cordova && window.cordova.plugins && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if (window.StatusBar) {
      StatusBar.styleDefault();
    }
  })
}
Run Code Online (Sandbox Code Playgroud)

实际上已经安装了cordova插件,它的类型定义文件肯定存在.这是文件tsd.d.ts.

/// <reference path="angularjs/angular.d.ts" />
/// <reference path="cordova/cordova.d.ts" />
/// <reference path="cordova/plugins/BatteryStatus.d.ts" />
/// <reference path="cordova/plugins/Camera.d.ts" />
/// <reference path="cordova/plugins/Contacts.d.ts" />
/// <reference path="cordova/plugins/Device.d.ts" />
/// <reference path="cordova/plugins/DeviceMotion.d.ts" />
/// <reference path="cordova/plugins/DeviceOrientation.d.ts" />
/// <reference path="cordova/plugins/Dialogs.d.ts" />
/// <reference …
Run Code Online (Sandbox Code Playgroud)

angularjs typescript ionic-framework

6
推荐指数
1
解决办法
2090
查看次数

我如何在目录结构中gitignore文件但保持目录结构?

我们假设我有一个像这样的目录结构:

app/
  uploads/
    .gitkeep
    images/
      .gitkeep
    videos/
      .gitkeep
    docs/
      .gitkeep
Run Code Online (Sandbox Code Playgroud)

我想保留dir结构但不包括文件(.gitkeep显然除外).文档说:

斜杠后跟两个连续的星号,然后斜杠匹配零个或多个目录.例如,"a/**/b"匹配"a/b","a/x/b","a/x/y/b"等.

所以,我希望这可以做到这一点:

/app/uploads/**
!/app/uploads/**/.gitkeep
Run Code Online (Sandbox Code Playgroud)

但这不起作用.没有添加任何子目录.

git

3
推荐指数
3
解决办法
4517
查看次数

将类添加到槽元素 (?)

在处理光照元素组件库时,我遇到了一个尴尬的场景。

我目前正在处理的组件是“警报”。在它的渲染模板中,它有两个命名槽:“title”和“text”。

<div class="alert-item-content">
   <i class="alert-item-icon"></i>
   <slot name="title"></slot>
   <slot name="text"></slot>
</div>
Run Code Online (Sandbox Code Playgroud)

分配给这些插槽的元素可能是任何有效的文本标签(h1、h2、h3 等)。我需要将插槽的分配元素定位到 A) 删除/重置影响它们的全局样式和 B) 添加对 UI 要求至关重要的特定样式。

因此,换句话说,一个人可能会提供一个“h5”,因为它在语义上是正确的,但作为一个警告标题,它应该始终显示相同。

例子:

<mult-alert>
  <mult-alert-item>
    <h5 slot="title">Notice Me</h5>
    <p slot="text">
      This is something you should probably
      <a href="#">pay attention to</a>
    </p>
  </mult-alert-item>
</mult-alert>
Run Code Online (Sandbox Code Playgroud)

到目前为止,我能想到的唯一解决方案是查询 shadowRoot 中分配的元素并向它们添加一个类。它确实有效,但感觉很糟糕。这是来自组件的相关代码:

addClassesToSlottedNodes() {
  [{
    slotName: 'title',
    className: 'alert-item-title'
  }, {
    slotName: 'text',
    className: 'alert-item-text'
  }].forEach(n => {
    const slotNodes = this.shadowRoot
      .querySelector(`slot[name="${n.slotName}"]`)
      .assignedNodes();

    if (slotNodes && slotNodes.length) {
      slotNodes[0].classList.add(n.className);
    }
  })
}
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来定位这些带槽的元素而不用这种方式添加类?或者,是否有更简洁的方法在组件模板中添加类?

web-component lit-element

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