Angular web services Architecture in ionic1


#1

Hello Guyz,

I am trying to build a hybrid app(android and ios) which can look up the content from local storage and internet files and populate the content(text) on application and save it in local storage for offline mode.

So is this application possible in ionic1, if so can I create angular(1.x) services and directives to achieve such functionality seperately, or Do I need to use ionic angular scopes and variables as well?

All I want to do is populate the content by first downloading it to local storage and then using the local storage to populate content and enable offline capability of the app.

For this Do I need to be an expert in angular or Can I write my own angular code and connect with <div>s on ionic pages?

ALL IONIC MASTERS AND TUTORS Please provide some suggestions …


#2

Hi @2909sanjay,

PWA in ionic

One solution is that you built ionic app with PWA.
PWA will cache your assets, css, web services, so once you opened app then if you goes offline your content, and webservice also cached. so you will use app in offline

Second solution is once you call php webservices you need to store that data in localStorage and then when app goes offline provide data from localStorage.

i used $http angular directive to call web services.


#3

@thaker U r the best

Second solution is once you call php webservices you need to store that data in localStorage and then when app goes offline provide data from localStorage.

This is the best solution and exactly what I want to do … on first launch I want to get the data from web and store it in local storage and then populate the downloaded text from the storage.

Friend do u have any existing code or codepen for such functionality?

How do you enable local storage in ionic1?


#4

Thank you.

the basic javascript, angular js functionality to store data in localStorage inherits here.

you can use window.localStorage. for storing data that comes in response of $http.

Here is one example of it.

$http.post(SERVER_URL + 'service1',parameters)
.then(function(r){ 
//example
window.localStorage.info = JSON.stringify(r.information);

//and to fetch data
$scope.info = JSON.parse(window.localStorage.info);

// to store data in localStorage and to fetch stringify() and parse() is preffered not compulsory
})
.catch(function(e){
// display error
})

This example is for ionic 1, i am also new in ionic 2.


#5

@thaker thank you

I am trying to build android app from ionic1.
Can I use building such functionality in ionic1 code separately and populate data on my div tags in ionic pages without using ionic directives and variables?