0

While using RadAutoCompleteTextView in nativescript-angular app,I'm facing this weird problem:
I build my project using "tns build android --bundle".App starts but RadAutocompleteCompleteTextView shows "no result found" although data bound to items attribute logs on terminal.

Now,if I make a minor change in my code(like delete a comment),it detect changes and auto rebuild again and this time AutocompleteView shows the data it was binding to. Also,now if I run my app over usb debugging it runs well but if I remove usb and restart app it shows error

Error:View already has a parent

Here are the html and ts files :

app.component.html

<ActionBar title="Lestrange" class="actionbar" [height]="abarVisible">
    <!-- <Image  src="~/app/assets/men.png" height='50' width='50'></Image>-->
    <NavigationButton icon="~/app/assets/menu.png" (tap)="onOpenDrawerTap()" [visibility]="getMenuVisible ? 'visible' : 'hidden'"></NavigationButton>
    <ActionItem class="name" [visibility]="SearchVisible ? 'visible' : 'hidden'">
        <StackLayout backgroundColor="#66cdaa" height="60" width="150" #action>
            <RadAutoCompleteTextView [items]="searchdata" (didAutoComplete)="onDidAutoComplete($event)" *ngIf="searchdata" #aitem>
                <SuggestionView tkAutoCompleteSuggestionView>
                    <ng-template tkSuggestionItemTemplate let-item="item">
                        <StackLayout orientation="vertical" padding="10">
                            <ImageCacheIt [src]="item.image" class='img' height='170' width='100' stretch="fill"></ImageCacheIt>
                            <Label [text]="item.id"></Label>
                        </StackLayout>
                    </ng-template>
                </SuggestionView>
            </RadAutoCompleteTextView>
        </StackLayout>
    </ActionItem>
    <ActionItem>
        <Label text="Search" color="white" (tap)="opensearch()"></Label>
    </ActionItem>
</ActionBar>
<RadSideDrawer backgroundColor="transparent" id="rd" [gesturesEnabled]="sideDrawerEnabled">
    <GridLayout tkDrawerContent rows="auto, *, auto" class="root-drawer-content">
        <StackLayout tkDrawerContent>
            <StackLayout height="56" marginTop="50" style="text-align: center; vertical-align: center;">
                <Label text="Menu" fontSize="27"></Label>
            </StackLayout>
            <StackLayout margin="25">
                <Label text="Home" [nsRouterLink]="['/hh']" padding="10" (tap)="onCloseDrawerTap()" fontSize="20" class="lbl"></Label>
                <Label text="Live" [nsRouterLink]="['/lil']" padding="10" (tap)="onCloseDrawerTap()" fontSize="20" class="lbl"> </Label>
                <Label text="Movies" [nsRouterLink]="['/moe']" padding="10" (tap)="onCloseDrawerTap()" fontSize="20" class="lbl"></Label>
                <Label text="TV Shows" [nsRouterLink]="['/ss']" padding="10" (tap)="onCloseDrawerTap()" fontSize="20" class="lbl"></Label>
                <Label text="Hindi" [nsRouterLink]="['/dhh']" padding="10" (tap)="onCloseDrawerTap()" fontSize="20" class="lbl"></Label>
            </StackLayout>
            <Label text="Logout" color="lightgray" padding="15" style="horizontal-align: center" (tap)="logout()" fontSize="20"> </Label>
        </StackLayout>
    </GridLayout>
    <page-router-outlet tkMainContent actionBarVisibility="never"></page-router-outlet>
</RadSideDrawer>

app.component.ts:`

 import {registerElement} from "nativescript-angular/element-registry";
    registerElement("exoplayer", () => require("nativescript-exoplayer").Video);
    import { Component,OnInit, ViewChild,AfterViewInit,OnChanges,AfterContentInit} from "@angular/core";
    //import { isAndroid } from "tns-core-modules/platform";
    import { Page } from "tns-core-modules/ui/page";
    import { RouterExtensions } from "nativescript-angular/router";
    import * as ApplicationSettings from "@nativescript/core/application-settings";
    const firebase = require("nativescript-plugin-firebase");
    import { RadSideDrawerComponent} from "nativescript-ui-sidedrawer/angular";
    import {FirebaseService} from '../app/services/firebase.service';
    import { RadAutoCompleteTextViewComponent } from "nativescript-ui-autocomplete/angular";
    import { TokenModel, AutoCompleteCompletionMode, AutoCompleteDisplayMode, AutoCompleteSuggestMode } from "nativescript-ui-autocomplete";
    import { ObservableArray } from "tns-core-modules/data/observable-array"
    import { Observable } from "rxjs";
    import "rxjs/add/operator/merge";
    import { MovieModel } from "./models/movie.model";
    import { NavigationExtras } from "@angular/router";
    ​
    @Component({
        selector: "ns-app",
        templateUrl: "app.component.html"
    })
    export class AppComponent implements OnInit,AfterViewInit,AfterContentInit{
    ​
      @ViewChild(RadSideDrawerComponent, { static: false }) public drawerComponent: RadSideDrawerComponent;
    ​
      public isAuth: boolean;
      public sideDrawerEnabled:boolean=false;
      public getMenuVisible:boolean=true;
      public abarVisible:number=70;
      public searchvar: boolean;
      public searchdata: ObservableArray<MovieModel>;
      public searchdata1: ObservableArray<MovieModel>;
    ​
      public datas$:Observable<any>;  
      public SearchVisible: boolean=false;
    ​
        constructor(private page: Page,public router:RouterExtensions,public firebaseService: FirebaseService) { }
    

 ngAfterContentInit(): void {
        
        }
      
      ngAfterViewInit(): void {
        
      //      //ApplicationSettings.setBoolean("authenticated", false);
      //      console.log(this.searchdata);
      //     //},2);
          }
     
    ​
    ​
    ​
        public ngOnInit() { 
          
               
            firebase.init({
                
              }).then(
                () => {
                  console.log("firebase.init done");
                },
                error => {
                  console.log(`firebase.init error: ${error}`);
                }
              );

          /////////////////////////////////////////////////////
             // console.log("fir"+this.getMenuVisible);
             this.firebaseService.AbarVisibleEnabled.subscribe(x=>this.abarVisible=x);
             this.firebaseService.SearchVisibleEnabled.subscribe(x=>this.SearchVisible=x);
    ​
              this.firebaseService.sideDrawerEnabled.subscribe(x=>this.sideDrawerEnabled=x);
              this.firebaseService.MenuVisibleEnabled.subscribe(y=>this.getMenuVisible=y);
             // console.log("fir"+this.getMenuVisible);
             this.searchdata = new ObservableArray<MovieModel>();
             this.datas$ = <any>this.firebaseService.getMyWishList('/index');
           // this.searchdata=this.firebaseService.fetchsearchdata();
           // this.searchdata1=this.searchdata;
           //          console.log(this.searchdata);
         
         
           //  // setTimeout(()=>{
         
                this.datas$.subscribe(datas=>{
                    datas.map(x=>{console.log(x);
                        this.searchdata.push(new MovieModel(x.id,x.c,x.img));
                    })
                });
             //this.drawer = this.drawerComponent.sideDrawer;
             if(this.router.router.url==='/login'){
              this.isAuth=true;
          }else{
              this.isAuth=false;
          }
        }
    ​
        public onDidAutoComplete(args) {

    this.SearchVisible=false;
    console.log(args.text.split(",")[0]);
    console.log(args.text.split(",")[1].trim());
    this.searchvar=false;
    ​
    let navigationExtras: NavigationExtras = {
      queryParams: {
          
          "showId": args.text.split(",")[0].trim(),
          "fromRoute":args.text.split(",")[1].trim()
    ​
      }
    };
    this.router.navigate(["/show-detail"],navigationExtras);
     }
       
      
  onOpenDrawerTap() {
          this.drawerComponent.sideDrawer.showDrawer();
      }
    
 onCloseDrawerTap() {
          this.drawerComponent.sideDrawer.closeDrawer();
      }
    ​
    
  get dataItems(): ObservableArray<MovieModel> {
        return this.searchdata;
    }
        
    
  opensearch(){
        this.SearchVisible=!this.SearchVisible;
        
      }
    ​
        public logout() {
          this.onCloseDrawerTap();
          ApplicationSettings.setBoolean("authenticated", false);
            //ApplicationSettings.remove("authenticated");
            this.router.navigate(["/login"], { clearHistory: true });
          }
    }

`

Although I don't have much knowledge about angular lifecycle hooks but I have a feeling that its about angular hooks ,So I tried to use differnet hooks but to no avail.Please help me find the issue in my code.Thanks in advance.

1 Answers1

0

It looks like you have an unpaired </StackLayout> tag in your html file. It is right after `.

I think you should remove that and see if that resolves the issue.

Hope this helps!

Tyler Blake
  • 136
  • 4