简体   繁体   English

将ts标签中的离子标签附加到html

[英]Append Ionic Tags from ts file to html

I am trying to add a div on the HTML file in my ionic app. 我正在尝试在离子应用程序的HTML文件中添加div。 I have created new Div and append it to the primary div in the HTML file using .innerHTML but the ionic tags are not being applied. 我已经创建了新的Div,并使用.innerHTML将其附加到HTML文件中的主div,但是未应用ionic标记。

MY html file 我的html文件

 <div class="vehicle-profile" id="vehicle-profile" style="padding-bottom: 10px;">
    <div class="upload">
        <ion-grid>
          <ion-row>
            <ion-col col-2>
              <div class="upload-small" (tap)="scanBarcode(i)">
                <img src="assets/icon/barcode.png" width="50px">
                <p style="margin: 0"> SCAN</p>
              </div>
            </ion-col>
            <ion-col offset-1 col-9>
              <input type="text" class="formfield" placeholder="VIN #" [(ngModel)]="vin[i]"  name="vin_number[{{i}}]" (ngModelChange)="getVehicleInfo($event, i)">
            </ion-col>
            <ion-col col-6>
                <input type="text" class="formfield" placeholder="Year" [(ngModel)]="year[i]" name="year[{{i}}]">
            </ion-col>
            <ion-col col-6>
                <input type="text" class="formfield" placeholder="Make"  [(ngModel)]="make[i]"  name="make[{{i}}]">
            </ion-col>
            <ion-col col-12>
                <input type="text" class="formfield" placeholder="Model" [(ngModel)]="model[i]"  name="model[{{i}}]">
            </ion-col>
            <ion-col col-6>
                <input type="text" class="formfield" placeholder="Plate #" [(ngModel)]="plate_num[i]" name="plat_number[{{i}}]">
            </ion-col>
            <ion-col col-6>
                <input type="text" class="formfield" placeholder="Mileage" [(ngModel)]="mileage[i]" name="mileage[{{i}}]">
            </ion-col>
            <ion-col offset-4 col-4>
                <div class="delete-btn" >
                    <button type="button" ion-button block large (click)="removeVehicleBox(i)">
                      <p class="{{i}}">
                          Delete Profile
                      </p>
                    </button>
                  </div>
            </ion-col>
          </ion-row>
        </ion-grid>
      </div>
</div>

when i append the same from the .ts file, it wont show the css effect. 当我从.ts文件中追加相同内容时,它不会显示css效果。

TS file TS文件

 addVehicleBox(){
    this.num = this.num+1;
    var content = document.createElement('div');      
    content.innerHTML = this.uploadBoxForm(this.num);
    document.getElementById('vehicle-profile').appendChild(content);
  }

  removeVehicleBox(selectedBox){
    console.log(selectedBox)
  }

  uploadBoxForm(i){
    let data = `
    <div class="upload">
    <ion-grid>
      <ion-row>
        <ion-col col-2>
          <div class="upload-small" (tap)="scanBarcode(`+i+`)">
            <img src="assets/icon/barcode.png" width="50px">
            <p style="margin: 0"> SCAN</p>
          </div>
        </ion-col>
        <ion-col offset-1 col-9>
          <input type="text" class="formfield" placeholder="VIN #" [(ngModel)]="vin[`+i+`]"  name="vin_number[`+i+`]" (ngModelChange)="getVehicleInfo($event, i)">
        </ion-col>
        <ion-col col-6>
            <input type="text" class="formfield" placeholder="Year" [(ngModel)]="year[`+i+`]" name="year[`+i+`]">
        </ion-col>
        <ion-col col-6>
            <input type="text" class="formfield" placeholder="Make"  [(ngModel)]="make[`+i+`]"  name="make[`+i+`]">
        </ion-col>
        <ion-col col-12>
            <input type="text" class="formfield" placeholder="Model" [(ngModel)]="model[`+i+`]"  name="model[`+i+`]">
        </ion-col>
        <ion-col col-6>
            <input type="text" class="formfield" placeholder="Plate #" [(ngModel)]="plate_num[`+i+`]" name="plat_number[`+i+`]">
        </ion-col>
        <ion-col col-6>
            <input type="text" class="formfield" placeholder="Mileage" [(ngModel)]="mileage[`+i+`]" name="mileage[`+i+`]">
        </ion-col>
        <ion-col offset-4 col-4>
            <div class="delete-btn" >
                <button type="button" ion-button block large (click)="removeVehicleBox(`+i+`)">
                  <p class="{{i}}">
                      Delete Profile
                  </p>
                </button>
              </div>
        </ion-col>
      </ion-row>
    </ion-grid>
  </div>
    `
    return data;
  }

Here, i have attached the image Showing the effect of using the ion tags in inner html from ts file. 在这里,我已附上图片,显示了从ts文件在内部html中使用ion标签的效果。 1 is the ion tags written in html file and 2 is the appended ion tags from ts file. 1是用html文件编写的离子标签,2是ts文件中附加的离子标签。 图片 .

Is there anyway that i could render the ion tags ? 无论如何,我可以渲染离子标签吗?

Are you sure you are adding the css classes and code? 您确定要添加CSS类和代码吗? I see your second example without 我看到你的第二个例子

"style="padding-bottom: 10px;"

Could be you are missing css styles in your 可能是您缺少CSS样式

var content = document.createElement('div');  

?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM