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



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

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.

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

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

这真的取决于你在做什么。如果你想在各种控制器中重用display,并且想要所有这些可配置性,那么这就是你的选择。

如果你对ctrl.stateService.display.content的长度感到恼火,你可以display直接放在$scope上,例如$scope.display = this.stateService.display,你会得到:

ng-show="display.content"

但这真的取决于你。

最新更新