小编Mar*_*ahl的帖子

ng-model不会触发更改事件

我正在使用的框架(jQuery Mobile)侦听textareas的更改事件以更改标记.这是框架代码,所以我不能改变它并包含正确的AngularJS函数.

我通过ng-model将textarea绑定到范围变量.当范围变量发生变化(因此textarea内容因为它被绑定)时,不会触发javascript change事件.但是,如果没有更改事件,jQuery Mobile无法更改标记.

是否有内置的方法让Angular在不编写指令的情况下触发更改事件?如果我使用指令或ng-change,我必须在textarea元素的每次出现时添加相应的代码.

我正在尝试做的简短示例(也可用作jsFiddle):

<div ng-app="app" ng-controller="Controller">
    <textarea ng-model="textValue"></textarea>
</div>

<script type="text/javascript>
var module = angular.module("app",[]);

module.controller("Controller", function ($scope) {
   $scope.textValue = "Test"; 

   window.setInterval(function () {
       $scope.textValue = $scope.textValue === "Test" ? "Hello World" : "Test";
       $scope.$apply();
   },2000);
});

//Dummy framework code which I do not have access to
document.querySelector("textarea").addEventListener("change", function () {
  alert("changed");
});
</script>
Run Code Online (Sandbox Code Playgroud)

模型更新时,不会触发任何更改事件.如果您键入textarea并单击外部(基本textarea更改),则会触发change事件.

javascript angularjs angular-ngmodel

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

合并不同文件中的 Typescript 接口和类

在 Typescript 中,如果接口和类具有相同的名称并且位于同一文件中,则可以合并它们:

interface Test {
  example(input: 'a number'): number;
  example(input: 'a string'): string;
}

class Test {
  example(input: string): any {
    //return something
  }
}

const obj = new Test();
obj.example('a number'); //return type is number
obj.example('a string'); //return type is string
obj.example('something else'); //return type is any
Run Code Online (Sandbox Code Playgroud)

然而,似乎没有办法将这些接口定义拆分为多个文件,例如:

//test.interface.ts
export interface Test {
  example(input: 'a number'): number;
  example(input: 'a string'): string;
}

//test.class.ts
import "./test.interface.ts";

class Test {
  example(input: string): any {
    //return something
  }
}

const obj …
Run Code Online (Sandbox Code Playgroud)

typescript

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