import { SecurityContext } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; private sanitizer: DomSanitizer; downloadCSV() { let blob = new Blob([yourdata], { type: 'text/csv' }); let urlPath = this.sanitizer.sanitize(SecurityContext.URL, this.sanitizer.bypassSecurityTrustResourceUrl(window.URL.createObjectURL(blob))); let tempLink = document.createElement('a'); tempLink.href = urlPath; tempLink.setAttribute('download', 'download.csv'); tempLink.click(); }
ionic
Google Android Play Store Target API Requirement Change
Hello Google Play Developer,
This is a reminder that starting November 1, 2019, updates to apps and games on Google Play will be required to target Android 9 (API level 28) or higher. After this date, the Play Console will prevent you from submitting new APKs with a targetSdkVersion less than 28.
Configuring your app to target a recent API level ensures that users benefit from significant security and performance improvements, while still allowing your app to run on older Android versions (down to the minSdkVersion).
Android 9 (API level 28) introduces a number of changes to the Android system. The following behavior changes apply exclusively to apps that are targeting API level 28 or higher. Apps that set targetSdkVersion to API level 28 or higher must modify their apps to support these behaviors properly, where applicable to the app.
To target the api in your Cordova app set these min and target version in config.xml
<preference name="android-minSdkVersion" value="23" /> <preference name="android-targetSdkVersion" value="28" />
iOS Deprecated API Usage Warning Ionic using UIWebView
Apple will no longer support web apps that use UIWebView. The apps and libraries need to be migrated to use WkWebView.
The latest Ionic already uses WkWebView, but several Cordova plugins still rely on UIWebView which is a problem.
https://ionicframework.com/docs/v3/wkwebview/
If you’re using Ionic you need to upgrade to iOS Cordova 5
cordova platform remove ios cordova platform add ios@5.0.0
Also you might need to remove additional plugins that use UIWebView such as inappbrowser.
cordova plugin rm cordova-plugin-inappbrowser
More information about the breaking changes can be found here:
https://cordova.apache.org/news/2018/08/01/future-cordova-ios-webview.html
CORS error when reading remote .json file
The easy fix to allow your Web App to read remote json files from the server is to create the .htaccess file.
Create an `.htaccess` file and place it in the directory of the json files.
<Files "*.json"> Header set Access-Control-Allow-Origin "*" </Files>
Simply reload your app and it should work! good luck!
How to Enable Preflight CORS in PHP for Angular HTTP requests
When testing Ionic or Angular app you might need to set CORS policy to access a service on a different domain. One way to do this in PHP for testing is to send OK responses for all OPTIONS requests. (If you are testing POST and GET requests)
In your php file set:
// change to your app origin header('Access-Control-Allow-Origin: http://localhost:8100'); header ("Access-Control-Expose-Headers: Content-Length, X-JSON"); header ("Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS"); header ("Access-Control-Allow-Headers: Content-Type, Authorization, Accept, Accept-Language, X-Authorization"); header('Access-Control-Max-Age: 86400'); if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { // The request is using the POST method header("HTTP/1.1 200 OK"); return; }
Don’t ship this test code, this is just for your internal testing of http requests.
How to mask and unmask input element password type in Ionic / Angluar
How to mask and unmask input element password type in ionic/angular/js:
this.togglePasswordField = function () { console.log("toggle password field called"); if (document.getElementById("passwordElement").type == "password") { document.getElementById("passwordElement").type = "text"; document.getElementById("passwordHideIcon").classList.remove("ion-eye"); document.getElementById("passwordHideIcon").classList.add("ion-eye-disabled"); } else { document.getElementById("passwordElement").type = "password"; document.getElementById("passwordHideIcon").classList.remove("ion-eye-disabled"); document.getElementById("passwordHideIcon").classList.add("ion-eye"); } }
This way only uses basic html element manipulation.
passwordHideIcon element is a button that calls the function and uses the ionic icon for eyes and eyes disabled.