Search code examples
nativescriptnativescript-angular

How to get NativeScript image from resources in TypeScript?


In template I can get images like: res:imageName

How to get image from typescript code? Just specify full path to resource file?


Solution

  • It is the same in code as well. res://image in your html

    <Image [src]="getImageSource(logo_white_bg)" stretch="none" class="img-rounded p-l-15 p-r-15 p-t-15"></Image>
    

    In case you want to save images in specific folder(e.g. 'logos') for ios in your .ts file

    getImageSource(icon: string) {
            return isAndroid ? `res://${icon}` : 'res://logos/' + icon;
        }