Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  132] [ 3]  / answers: 1 / hits: 35237  / 10 Years ago, tue, june 17, 2014, 12:00:00

Before I am using JQuery and I use this to send URL with parameter



window.location = myUrl + $.param({paramName : ok,anotherParam:hello});


but with angularjS this does not work the same way



$scope.myButton = function() {
$window.location.open = myUrl + $.param({paramName : ok,anotherParam:hello});
};//Error: $ is not defined


can anyone help me how to do this in angularJs


More From » jquery

 Answers
23

If you are trying to create serialized representation of data like $.param() does,



function serializeData( data ) { 
// If this is not an object, defer to native stringification.
if ( ! angular.isObject( data ) ) {
return( ( data == null ) ? : data.toString() );
}

var buffer = [];

// Serialize each key in the object.
for ( var name in data ) {
if ( ! data.hasOwnProperty( name ) ) {
continue;
}

var value = data[ name ];

buffer.push(
encodeURIComponent( name ) + = + encodeURIComponent( ( value == null ) ? : value )
);
}

// Serialize the buffer and clean it up for transportation.
var source = buffer.join( & ).replace( /%20/g, + );
return( source );
}


and use this for your data serialization


[#70542] Saturday, June 14, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tina

Total Points: 91
Total Questions: 106
Total Answers: 104

Location: Vanuatu
Member since Fri, May 13, 2022
2 Years ago
;