在多个视图中使用组件的单个实例

时间:2019-02-26 13:51:37

标签: angularjs

在我的Option Explicit Private pColA As String Private pColB As String Private pColCConcat As String Private pColHConcat As String Private pColIConcat As String Private pColJConcat As String Private pColKConcat As String Private pColLConcat As String 'step 1 A Public Property Get ColA() As String ColA = pColA End Property 'step 2 A Public Property Let ColA(Value As String) pColA = Value End Property 'step 1 B Public Property Get ColB() As String ColB = pColB End Property 'step 2 B Public Property Let ColB(Value As String) pColB = Value End Property 'step 1 concat C Public Property Get ColCConcat() As String ColCConcat = pColCConcat End Property 'step 2 concat C Public Property Let ColCConcat(Value As String) pColCConcat = Value End Property 'step 1 concat H Public Property Get ColHConcat() As String ColHConcat = pColHConcat End Property 'step 2 concat H Public Property Let ColHConcat(Value As String) pColHConcat = Value End Property 'step 1 concat J Public Property Get ColJConcat() As String ColJConcat = pColJConcat End Property 'step 2 concat J Public Property Let ColJConcat(Value As String) pColJConcat = Value End Property 'step 1 concat I Public Property Get ColIConcat() As String ColIConcat = pColIConcat End Property 'step 2 concat I Public Property Let ColIConcat(Value As String) pColIConcat = Value End Property 'step 1 concat K Public Property Get ColKConcat() As String ColKConcat = pColKConcat End Property 'step 2 concat K Public Property Let ColKConcat(Value As String) pColKConcat = Value End Property 'step 1 concat L Public Property Get ColLConcat() As String ColLConcat = pColLConcat End Property 'step 2 concat L Public Property Let ColLConcat(Value As String) pColLConcat = Value End Property Option Explicit Sub CombineData() Dim cCombData As Combdata Dim colCombData As Collection Dim V As Variant Dim vRes() As Variant 'Results Array Dim rRes As Range 'Location of results Dim I As Long 'read source data into array V = Range("A1", Cells(Rows.Count, "A").End(xlUp)).Resize(columnsize:=13) 'Set results range. Here it is set below the Source Data 'Could be anyplace, even on a different worksheet; or could overlay the ' original. Area below and to right is cleared Sheets.Add After:=Sheets(Sheets.Count) Set rRes = Sheets(Sheets.Count).Range("A1") Range(rRes, rRes.SpecialCells(xlCellTypeLastCell)).Clear 'code to grab all data that will be used Set colCombData = New Collection On Error Resume Next For I = 1 To UBound(V) Set cCombData = New Combdata cCombData.ColA = V(I, 1) cCombData.ColB = V(I, 2) cCombData.ColCConcat = V(I, 3) cCombData.ColHConcat = V(I, 7) cCombData.ColIConcat = V(I, 8) cCombData.ColJConcat = V(I, 9) cCombData.ColKConcat = V(I, 10) cCombData.ColLConcat = V(I, 11) colCombData.Add cCombData, CStr(cCombData.ColA) < ---Error line 'if statement to concatenate specified columns If Err.Number <> 0 Then Err.Clear With colCombData(cCombData.ColA) .ColCConcat = .ColCConcat & ", " & Chr(10) & V(I, 3) .ColHConcat = .ColHConcat & ", " & Chr(10) & V(I, 7) .ColIConcat = .ColIConcat & ", " & Chr(10) & V(I, 8) .ColJConcat = .ColJConcat & ", " & Chr(10) & V(I, 9) .ColKConcat = .ColKConcat & ", " & Chr(10) & V(I, 10) .ColLConcat = .ColLConcat & ", " & Chr(10) & V(I, 11) End With End If Next I On Error GoTo 0 'code to write new data in specified location ReDim vRes(1 To colCombData.Count, 1 To 13) For I = 1 To UBound(vRes) With colCombData(I) vRes(I, 1) = .ColA vRes(I, 2) = .ColB vRes(I, 3) = .ColCConcat vRes(I, 7) = .ColHConcat vRes(I, 8) = .ColIConcat vRes(I, 9) = .ColJConcat vRes(I, 10) = .ColKConcat vRes(I, 11) = .ColLConcat End With Next I rRes.Resize(UBound(vRes, 1), UBound(vRes, 2)) = vRes 'formatting With rRes .Range("A1:K1").Interior.ColorIndex = 48 .Range("A1:K1").Font.Bold = True .Range("A1", Cells(Rows.Count, "A").End(xlUp)).Resize(columnsize:=13).VerticalAlignment = xlTop .Range("A1", Cells(Rows.Count, "A").End(xlUp)).Resize(columnsize:=11).Borders.LineStyle = xlContinuous .Range("A1:K1").VerticalAlignment = xlCenter .Range("A1:K1").HorizontalAlignment = xlCenter Columns("a:a").ColumnWidth = 16.57 Columns("B:B").ColumnWidth = 13.71 Columns("C:C").ColumnWidth = 8.43 Columns("G:G").ColumnWidth = 7.29 Columns("H:H").ColumnWidth = 15.43 Columns("I:I").ColumnWidth = 45 Columns("J:J").ColumnWidth = 13.57 Columns("K:K").ColumnWidth = 15.43 Rows(2).RowHeight = 100 .Range("D:F").EntireColumn.Delete End With End Sub 中,我有:

topheader.html

在我的 <responsive-mode></responsive-mode> 中,我还有:

responsivenavigation.html

组件:

 <responsive-mode></responsive-mode>

还有html:

class ResponsiveModeComponent {
    public onlyShowOnSurfaceTablet: boolean;
    public currentMode: string;

    $onInit() {
        this.onlyShowOnSurfaceTablet = window.device.surface();
        if (window.device.surface()) {
            this.currentMode = 'desktop_windows';
        } else {
            this.currentMode = 'tablet_android';
        }
    }

    switchMode() {
        if (this.currentMode === 'desktop_windows') {
            this.currentMode = 'tablet_android';
            window.document.documentElement.className = window.document.documentElement.className.replace('tablet', 'desktop');
        } else {
            this.currentMode = 'desktop_windows';
            window.document.documentElement.className = window.document.documentElement.className.replace('desktop', 'tablet');
        }
    }
}

我希望用户能够根据需要在模式之间进行切换。这有点工作。但是在应用程序中似乎有该组件的2个实例。是否可以将在组件的一个实例中设置的值传递给组件的另一个实例?还是最好让2个组件共享1个组件实例?

0 个答案:

没有答案