打字稿和角度。铸造范围类型?

时间:2015-08-07 15:58:43

标签: angularjs casting scope typescript directive

在一个指令中,我有一些用于扩展范围的自定义逻辑。为此,我在收到的范围之外创建一个子范围。

$scope = scope.new(false);

但是在打字稿中,这会导致问题。我有一个名为ITableScope的指令范围的接口,它扩展了ng.IScope。抱怨ng.IScope不是ITableScope的可分配类型。

interface ITableScope extends ng.IScope {}
var $scope: ITableScope;
$scope = scope.$new(false);

所以我想也许我可以施放scope.$new,但它似乎并不知道我想要做什么。

interface ITableScope extends ng.IScope {}
var $scope: ITableScope;
$scope = (ITableScope) scope.$new(false);

我做错了什么?

1 个答案:

答案 0 :(得分:0)

当我回答自己的问题时,我喜欢它。

我做错了。你使用尖括号进行投射。

$scope = <ITableScope> scope.$new(false);

另外,感谢@musically_ut。我在写完帖子后几秒就发现了,但你的反应非常快!