用AngularJS和Typescript编写例程以显示HTML区域的好方法是什么?

用AngularJS和Typescript编写例程以显示HTML区域的好方法是什么?,angularjs,typescript,Angularjs,Typescript,到目前为止,我使用的方法与此类似: class StateService implements IStateService { display = { alert: null, content: null, header: null, init: null, modal: null, preview: null, } show = { modal: () =&

到目前为止,我使用的方法与此类似:

class StateService implements IStateService {

    display = {
        alert: null,
        content: null,
        header: null,
        init: null,
        modal: null,
        preview: null,
    }

   show = {
        modal: () => {
            this.display.content = false;
            this.display.header = false;
            this.display.modal = true;
            this.display.preview = true;
        },
        preview: () => {
            this.display.content = false;
            this.display.header = true;
            this.display.modal = false;
            this.display.preview = true;
        }
    }

}
我将stateService注入到我的控制器中,并且在我的HTML页面上有包含以下内容的div:

 ng-show="ctrl.stateService.display.content"  etc.
有没有更好的办法让我这么做。我现在的方式似乎不是一个非常干净的解决方案

有没有更好的办法让我这么做。我现在的方式似乎不是一个非常干净的解决方案

这取决于你在做什么。如果您希望在各种控制器中重复使用
显示
,并希望所有这些可配置性,那么这是一条可行的道路

如果您对
ctrl.stateService.display.content
的长度感到厌烦,您可以将
display
直接放在
$scope
上,例如
$scope.display=this.stateService.display
,您可以:

ng-show="display.content"
但这真的取决于你