小编miy*_*oro的帖子

AngularJS如何观看$ viewValue而不是ngModel?

我在输入上使用debounce:

<input type="text"
     ng-model="model.qty"
     ng-model-options="{ debounce : 1000 }"
     min="{{model.min}}" max="{{model.max}}" step="1"
     qty-input validate-model-setting>
Run Code Online (Sandbox Code Playgroud)

我有一个指令来处理禁用此输入的增量按钮和减量按钮:

app.directive('qtyInput', function() {
    return {
        restrict: 'A',
        require: '?ngModel',
        link: function(scope, element, attrs, ngModelCtrl) {
            scope.$watch(attrs.ngModel, function(n, o) {
                var val = parseInt(n);
                if(!isNaN(val)) {
                    if(val + 1 > model.max) {
                        scope.quantityIncDisabled = true;
                    } else {
                        scope.quantityIncDisabled = false;
                    }
                    if(val - 1 < model.min) {
                        scope.quantityDecDisabled = true;
                    } else {
                        scope.quantityDecDisabled = false;
                    }
                }
            });
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

问题是,该指令上的手表正在查看模型.我需要它来看看$viewValue.这是因为,由于去抖动,在输入中键入和使用递增/递减按钮之间存在竞争条件.例如,您可以在输入达到1(最小值)后反复单击减量按钮1秒钟,然后在去抖动结束后,减量按钮将被禁用.相反,我希望在输入达到1时立即禁用该按钮,而不是在等待完全去抖秒之后.我最好的猜测是,这意味着把一 …

javascript watch angularjs

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

Typescript 发出的声明找不到全局接口的名称

此问题位于私人 CDN 库中。我想生成 TypeScript 声明文件,供集成该库的应用程序开发使用。我的问题是,我生成的声明文件存在关于正确定义的全局接口的“找不到名称”错误。

首先,CDN库的编译选项有emitDeclarationOnly和declarationtrue。这正确地将声明放入目录“types”中。

 "compilerOptions": {
    "module": "es2020",
    "target": "es2020",
    "sourceMap": true,
    "checkJs": true,
    "allowJs": true,
    "emitDeclarationOnly": true,
    "declaration": true,
    "outDir": "types"

    // .... paths etc. omitted
  }
Run Code Online (Sandbox Code Playgroud)

其次,我有一个全局接口声明文件,它声明了大约 7 或 8 个不同的接口。

// global.ts
    interface ComponentToggle {
        component: HTMLElement,

        // other properties here
    }

    // more interfaces here
Run Code Online (Sandbox Code Playgroud)

第三,原始的JavaScript源文件能够使用JSDocs内部的全局接口。这些文件使用 JSDocs 来定义其 TypeScript 信息。它们编译成.d.ts文件时没有任何错误。

// otherfile.js
    /** Removes active state from all options.
     *
     * @param toggle {ComponentToggle} the parent element toggle …
Run Code Online (Sandbox Code Playgroud)

typescript

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

如何使用 webpack externalsType 模块

没有关于如何在使用 externalsType = module 时声明外部本身的文档,因此我一直在尝试我能想到的一切。

这是一个与不导出 ES6 模块的 CDN 版本配合使用的版本。

{
    "experiments": { outputModule: true },
    "output": {
         "path": path.join( __dirname, 'dist' ),
         "[name].mjs",
         "library": { type: "module" }
    }
   "externalsType": "var",
   "externals": {
       "/local/library.min.js": "library"  <-- this is the non-ES6-module version of the CDN
   }
}

// builds the correct output files
Run Code Online (Sandbox Code Playgroud)

我想做的是实际上导入 CDN 的 ES6 模块版本。

我尝试过的一些事情:

1.

   "externalsType": "module",
   "externals": {
       "/local/library.min.mjs": "https://cdn-path/library.min.mjs"
   }

// The target environment doesn't support EcmaScriptModule syntax so it's not possible to …
Run Code Online (Sandbox Code Playgroud)

webpack

5
推荐指数
2
解决办法
6607
查看次数

标签 统计

angularjs ×1

javascript ×1

typescript ×1

watch ×1

webpack ×1