Calling function from another function in ionic2 - ionic2

i want to call set function from var success function.
how to do this not able to use this.set()
getting this error http://prntscr.com/j1il36
please help
set(otp){
alert(otp);
this.otpData.otp = localStorage.getItem('otp');
}
smsRead(){
var options = {
delimiter : "OTP is",
length : 6,
origin : "ENTIND"
};
var success = function (otp) {
this.set(otp);
localStorage.setItem('otp', otp) ;
OTPAutoVerification.stopOTPListener();
}
var failure = function () {
OTPAutoVerification.stopOTPListener();
alert("Problem in listening OTP");
}
OTPAutoVerification.startOTPListener(options, success, failure);
}

Related

Cannot determine what is wrong with this action. Input Parameter is null

Using the following results in a null input error. Through debugging the plugin the input parameter is not being passed. Any ideas? I've done hundreds of these but never seen this type of issue.
tdn_GetFoxhoundNotesRequest = function (contactId) {
this.ContactId = contactId;
};
tdn_GetFoxhoundNotesRequest.prototype.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {
"ContactId": {
"typeName": "Edm.String",
"structurualProperty": 1
}
},
operationType: 0,
operationName: "tdn_GetFoxhoundNotes"
};
};
function LoadNotes(executionContext) {
var formContext = executionContext.getFormContext();
var contactId = formContext.data.entity.getId().replace("{", "").replace("}", "");
var request = new tdn_GetFoxhoundNotesRequest(contactId);
Xrm.WebApi.online.execute(request).then(
function success(result) {
if (result.ok) {
{
result.json().then(function (response) {
formContext.getAttribute("tdn_foxhoundnotestextblob").setValue(response.Notes);
formContext.getAttribute("tdn_foxhoundnotestextblob").setSubmitMode('never');
})
}
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
});
}

Call external function angular 2

I've a problem with facebook API,
I would like to call a function but I'm located in Facebook.api function so my function is not recognized because I'm encapsulated in Facebook object. Here is my code :
export class MyClass {
constructor(platform:Platform) {
}
function1(number_likes:number) {
var elem = document.getElementById('number_of_likes');
elem.innerHTML = ""+number_likes;
}
query_fan_numbers() {
var pageId = "81221197163?fields=fan_count";
Facebook.api(pageId, null)
.then(function(success) {
this.function1(parseInt(JSON.stringify(success.fan_count))); //Here's the error
}
}
My error is something like that : TypeError: Cannot read property 'function1' of null
How can I call the function1 function in my class ?
As #jonrsharpe mentioned
You can either use a fat arrow:
query_fan_numbers() {
var pageId = "81221197163?fields=fan_count";
Facebook.api(pageId, null)
.then((success)=> {
this.function1(parseInt(JSON.stringify(success.fan_count))); //Here's the error
}
}
or the the plain old javascript trick to store this in a variable to use later.
query_fan_numbers() {
var that = this;
var pageId = "81221197163?fields=fan_count";
Facebook.api(pageId, null)
.then(function(success) {
that.function1(parseInt(JSON.stringify(success.fan_count))); //Here's the error
}
}

How to enableMajor?

How could I enable Major versioning on "Pages" list? My code is not working and I don't get any errors. Any suggestions?....
_spBodyOnLoadFunctionNames.push(onPageLoad());
function onPageLoad() {
ExecuteOrDelayUntilScriptLoaded(enableMajor, 'SP.js')
}
function enableMajor() {
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle('Pages');
ctx.load(list);
ctx.executeQueryAsync(
function () {
list.enableMajor = true;
},
function (sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
);
}
UPDATE 06-15
====---------------
Major version will not set? i dont why it is not setted? Any suggestions?
<script>
var list;
function getPublishingPages(success, error) {
var ctx = SP.ClientContext.get_current();
list = ctx.get_web().get_lists().getByTitle('Pages');
var items = list.getItems(SP.CamlQuery.createAllItemsQuery());
ctx.load(items, 'Include(File)');
list.set_e
ctx.executeQueryAsync(function () {
success(items);
},
error);
}
SP.SOD.executeFunc('SP.js', 'SP.ClientContext', function () {
getPublishingPages(printPagesInfo, logError);
});
function printPagesInfo(pages) {
pages.get_data().forEach(function (item) {
var file = item.get_file();
var pageStatus = file.get_level() === SP.FileLevel.published ? 'published' : 'not published';
alert(String.format('Page {0} is {1}', file.get_name(), pageStatus));
list.set_enableVersioning(true);
list.update();
alert('Major versioning enabled');
});
}
function logError(sender, args) {
alert('An error occured: ' + args.get_message());
}
</script>
In order to enable Create major versions the following steps should be performed:
set SP.List.enableVersioning property to true
call SP.List.update Method to update the list
Example
function enableListVersioning(listTitle,success,error) {
var ctx = SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle(listTitle);
list.set_enableVersioning(true);
list.update();
ctx.executeQueryAsync(
function () {
success();
},
error);
}
//usage
enableListVersioning('Pages',
function(){
console.log('Versioning is enabled');
},
function(sender,args){
console.log('An error occured: ' + args.get_message());
});

if control does not work using check box

I cannot manage to handle the 'check-box handler', a problem, that I have traced back to happen obviously within the if-control function.
If you try the following modified code, you see, that the Boolean-variable "e.parameter.myCheckBox" yields the correct result, the if-branching-off based on this variable, however, does not work. Does anyone see the mistake here?
Thank you very much
Martin
function ifTest(e) {
var app = UiApp.createApplication().setTitle('ifTest');
var panel = app.createVerticalPanel();
var grid = app.createGrid(3, 3);
var myCheckBox = app.createCheckBox().setName('myCheckBox').setId('myCheckBox');
var button = app.createButton('submit').setId("submit").setWidth("280").setHeight("35");
grid.setWidget(1, 0, app.createLabel('Check for True').setStyleAttribute("font-size", "110%"));
grid.setWidget(1, 1, myCheckBox);
grid.setWidget(2, 1, button);
var handler = app.createServerHandler('ifCheck');
var handler = app.createServerClickHandler('ifCheck');
handler.addCallbackElement(myCheckBox);
myCheckBox.setValue(false, false);
handler.addCallbackElement(grid);
button.addClickHandler(handler);
panel.add(grid);
app.add(panel);
ss.show(app);
return app;
}
function ifCheck(e) {
var bCBresult = e.parameter.myCheckBox;
var app = UiApp.getActiveApplication();
Browser.msgBox(bCBresult);
if (bCBresult) {
Browser.msgBox("bCBresult = true");
}
else {
Browser.msgBox("bCBresult = false");
};
return app.close();
}
the value returned by e.parameter.myCheckBox is a string, not a boolean. (that's actually the case for all e.parameter values..., they are always strings)
So your condition would be if (bCBresult=='true') {

How to call web service from flex

I have some problem with calling web service from flex. I have service with name UserService with one method string GetData(int i). I want to call this method from flex and get data. My code is here:
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
uService = new UserService();
uService.addEventListener("hello", echoResultHandler);
uService.GetData(1);
}
public function echoResultHandler(event:ResultEvent):void {
var retStr:String = event.result as String;
var retInt:int = event.result.echoInt;
Alert.show('want to play', retStr);
}
Might be my question is not difficult, but I can't understand why it does't works.. Can anybody help me?
Service code, generated by flex when I added reference to servese.
internal class _Super_UserService extends com.adobe.fiber.services.wrapper.WebServiceWrapper
{
public function _Super_UserService()
{
_serviceControl = new mx.rpc.soap.mxml.WebService();
var operations:Object = new Object();
var operation:mx.rpc.soap.mxml.Operation;
operation = new mx.rpc.soap.mxml.Operation(null, "GetData");
operation.resultType = String;
operations["GetData"] = operation;
_serviceControl.operations = operations;
try
{
_serviceControl.convertResultHandler = com.adobe.serializers.utility.TypeUtility.convertResultHandler;
}
catch (e: Error)
{ }
preInitializeService();
model_internal::initialize();
}
protected function preInitializeService():void
{
_serviceControl.service = "UserService";
_serviceControl.port = "BasicHttpBinding_IUserService";
wsdl = "http://localhost:3905/UserService.svc?wsdl";
model_internal::loadWSDLIfNecessary();
}
public function GetData(value:int) : mx.rpc.AsyncToken
{
model_internal::loadWSDLIfNecessary();
var _internal_operation:mx.rpc.AbstractOperation = _serviceControl.getOperation("GetData");
var _internal_token:mx.rpc.AsyncToken = _internal_operation.send(value) ;
return _internal_token;
}
}
Inherited class:
public class UserService extends _Super_UserService
{
protected override function preInitializeService():void
{
super.preInitializeService();
// Initialization customization goes here
}
}
Your UserService class never dispatches an event named "hello"; so therefore your result handler will never be fired. I think you need to add a result handler to the ASynctoken.
var call : Asynctoken = uService.GetData(1);
call.addResponder( new AsyncResponder(echoResultHandler) );
more info on the AsyncResponder and AsyncToken