Reputation: 3137
I am trying to implement Web intent and need to show popup when user shared something with my app and want to get some text.
if (window.plugins && window.plugins.webintent) {
var incomingURL;
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_TEXT,function(url) {
incomingURL = url
var myPopup = messageAlert.saveData(url);
}, function() {
incomingURL = false;
}
);
Here messageAlert is a factory. I want to show a modal or popup where user can input some text and i can use furture.
.factory('messageAlert', function ($ionicPopup,$timeout,$ionicModal) {
return {
saveData : function(url) {
// here i tried different scenes. but nothing work out.
// i want a form where user can input some data and save
}
}
}
Can anybody give me idea
Upvotes: 1
Views: 645
Reputation: 71
As far as I understand, your problem is not about getting the webintent to work, but simply to display the $ionicPopup
.
So the main issue I see, is that you inject the $ionicPopup
within a factory. Since you want to display the popup on a view, you need to inject it in your controller. There you can create a popup like this:
$ionicPopup.prompt({
title: 'Your title text',
template: 'Please enter your text here',
inputType: 'text',
inputPlaceholder: 'Your text here'
}).then(function(res) {
// after the user typed something, this result callback will be called
// res will contain the text which your user entered
});
You can find the corresponding docs with possible settings here.
Trying to merge this with your code above, I would suggest something like this:
.controller('YourCtrl', function($ionicPopup, messageAlert) {
this.someFunction = function() {
if (window.plugins && window.plugins.webintent) {
var incomingURL;
window.plugins.webintent.getExtra(window.plugins.webintent.EXTRA_TEXT,function(url) {
incomingURL = url;
// open the text input popup
var myPopup = $ionicPopup.prompt({
title: 'Your title text',
template: 'Please enter your text here',
inputType: 'text',
inputPlaceholder: 'Your text here'
});
// after the user typed something, this result callback will be called
myPopup.then(function(userText) {
// userText contains the text which your user entered
// now you can save the data with your factory
messageAlert.saveData(incomingURL, userText);
});
}, function() {
incomingURL = false;
});
}
};
});
Please note that I did not test the latter code, since I do not understand your exact use case.
Upvotes: 0
Reputation: 4739
Here are some ideas to debug the problem:
alert('YES THIS WORKS!')
in the messageAlert.saveData()
factory?Upvotes: 0