Im using $this->js(true, 'your js here');, but have a problem:
If certain conditions are met, i redirect page to something else, with js function like this:
top.location = "http://some-url.com?param1=AAA¶m2=BBBB"
but & character converts to: &
I know i can use $this->api->redirect('some-url', array('param1'=>AAA, 'param2'=>BBB));
But for some reasons i have to use js function, but only to write html characters properly.. How to acomplish this?
The proper way to do this:
if($condition){
$this->js(true)->univ()->location('http://some-url.com?param1=AAA¶m2=BBBB');
}
More information here: http://book.agiletoolkit.org/js/univ.html
Related
Could you explain me how to use Lodash _.template in order to get some value from script to .html file via {{data}} ?
For example:
In script.js I set some changes to my data object and in view.html. I want to get changed data with {{data}}
How to use lodash _.template() for this issue?
The lodash template function does not allow you to build templates from files (but you could do it when combined with Webpack). It has absolutely nothing to do with AngularJS templates. However in some situations it makes sense of using inside of AngularJS, like for example building a list of strings with a pattern or the like.
You compile a template string to a function you can call as often as you like with the values:
const executor = _.template("Hello <%= name %>, my old friend!");
console.log(executor({name: 'Alice'})); // Hello Alice, my old friend!
console.log(executor({name: 'Bob'})); // Hello Bob, my old friend!
You can also use conditional, loops, etc.: https://lodash.com/docs/4.17.15#template
I am using angular 1.5 and using translate to externalize my strings to a separate json file.
The translated strings sometimes fail to load and the path of the string is displayed instead.
ex: instead of displaying "Hello World" it displays something like "greet.hello".
This is not a regular occurrence and goes away when I refresh the page.
Not sure whether this is a file load issue.
Remove the single quote.
Its should be {{greet.hello | translate}}.
it's better practice to use directive.
Angular runs every single filter twice per $digest cycle once something has changed.
So you can do directive instead:
<h1 translate="{{greet.hello}}" ></h1>
In my Angular app, I want to sanitise any inputs to strip any/all tags, so even if a user entered <h1>superman</h1> the html tags would be stripped.
Now I've read about ngSanitize however on this docs page https://docs.angularjs.org/api/ngSanitize/service/$sanitize it mentions whitelist, so I presume that means Angular would accept things like <h1>.
Is my understanding in this correct?
And if so, how do i forcefully remove any and all tags from any input?
Thanks.
ngSanitize simply makes html safe, so it can't run javascript inside. You'd probably want to use the simple javascript replace method with a regex here.
something like:
var str = '<h1>superman</h1>';
str.replace(/<[^>]+>/g, '');
This would remove any XML tags, not just html.
please refer to this plnkr example
https://plnkr.co/edit/F9K3sekUQUJPBUts8Jdw?p=preview
var strip = function() {
var tmp = document.createElement("DIV");
tmp.innerHTML = $scope.strip; // assuming text box is using "strip" for ng-model
return tmp.textContent || tmp.innerText || "";
};
It can be done with simple Javascript. No need for ngSanitize or any other angularjs specific code.
We are using DPS's PXPay to generate payments for our app.
On a successful transaction the url that is provided looks like
http://ourapp.com/checkout/complete?result=v5eX-DlMlfGe2FUcPeZgCFiKhZwgmCVhlTfL-rtnPszpe8S_6MYJMbVPDK14h7KxQM6xfKYUnXhz_RcSOHqw4VwHX97GU9XINHwh9DFt6aDHOLMvdAnSwZost5H2aOQlZgMESDzlwNGx_lfgeLba2Us41x437J3PWTJ_LLJVK4OY_7K4c6rxQ88Mve7FfoYd7P8CAZWxyHbC-wxCyLiocw4_NQ_34ct-IAsR1MM3C2OkPijfBAk-l72rOOMWGp8EoLpdOHyT0uITvsdjMvOFIHIMnSdVs2JFCslAmTRMDl4jkb5ezBf9wKZuo91KgII0kd9dFJMFCm7evt-X0ykLw_vjcgg85kZoRbDvi89nEGiWmFLVKM_xVgZYufeMMudOGRcHgi4i-RZJ4mml2JMzN2OtJKyQdpxuC-3b9KfnRbyy_F75Gak5fwJIf4tvo6VNJKUJuBtKYKafPyH_YJU4HQMeHP8uO0-FhMN3mzRCmGjvExuqx1BhA67R35pmaTbyxz-06JEvIqzf8FTftoBowLSeu37KtNmagZ8cJpMlCe4kUaFY4v6ZTx7h9rYx37oYtZNsSR1t3KDFzQYRs5LAg8RQ==&userid=OurDevId
This is definitely the request that is coming into the browser. BUT what is displayed in my browser URL bar... and what angular reads for the "result" token is this...
http://ourapp.com/checkout/complete?result=v5eX-DlMlfGe2FUcPeZgCFiKhZwgmCVhlTfL-rtnPszpe8S_6MYJMbVPDK14h7KxQM6xfKYUnXhz_RcSOHqw4VwHX97GU9XINHwh9DFt6aDHOLMvdAnSwZost5H2aOQlZgMESDzlwNGx_lfgeLba2Us41x437J3PWTJ_LLJVK4OY_7K4c6rxQ88Mve7FfoYd7P8CAZWxyHbC-wxCyLiocw4_NQ_34ct-IAsR1MM3C2OkPijfBAk-l72rOOMWGp8EoLpdOHyT0uITvsdjMvOFIHIMnSdVs2JFCslAmTRMDl4jkb5ezBf9wKZuo91KgII0kd9dFJMFCm7evt-X0ykLw_vjcgg85kZoRbDvi89nEGiWmFLVKM_xVgZYufeMMudOGRcHgi4i-RZJ4mml2JMzN2OtJKyQdpxuC-3b9KfnRbyy_F75Gak5fwJIf4tvo6VNJKUJuBtKYKafPyH_YJU4HQMeHP8uO0-FhMN3mzRCmGjvExuqx1BhA67R35pmaTbyxz-06JEvIqzf8FTftoBowLSeu37KtNmagZ8cJpMlCe4kUaFY4v6ZTx7h9rYx37oYtZNsSR1t3KDFzQYRs5LAg8RQ&userid=OurDevId
If you look closely... the two '==' are being taken off the end of the "result" token string.
I've tested in non angular applications and this isn't happening. Why does angular do this and how do I prevent it?
Angular cannot handle == because of its $location's search parsing. Just visit : https://angularjs.org/?foo==123 and the url will change to https://angularjs.org/?foo=
The same will not happen on a non-angular page.
Solution: Either patch angular OR HTML encode the section after ?result=
Depending on what you're trying to do with the URL that is returned, it might be simpler to just set window.location directly instead of working through Angular. This bypasses the query-string parsing in $location that's stripping the double equals.
I'm trying to understand how can i configure my angularJS routing given the following case:
We have a search page where we display the search results based on tags provided (1..n tags). we would like that a user to be able to parse enter a url as the following and our system to do the search and show the respective results.
The url format should be:
http://mywebsite.com/search/<term1>/<term2>/<termN>...so it could be different number of terms.
I was looking into the route provide and couldn't figure out a way to do it dynamically.
i saw that i could put in the routeprovid:
.when('/search/:searchParams',... but that handles only when i have one term...is there anyway to configure it to take as many terms as is given?
Does this help you at all? Seems to support dynamic routing and you could probably cut apart the :name parameter to do what you wish, perhaps.
http://gregorypratt.github.io/AngularDynamicRouting/
Ken
You could try base64ing your searchParams:
.when('/search/:searchParams', {controller:'SearchCtrl'})
function SearchCtrl($routeParams, $location){
//Assuming your params are an array like ['param1', 'param2', 'param3']
//You could easily adapt this to base64 a JSON object
function encodeParams(params){
return window.btoa(params.join(';'));
}
function decodeParams(string){
return window.atob(string).split(';');
}
var searchParams = decodeParams($routeParams.searchParams);
scope.search = function(params){
$location.path('/search/' + encodeParams(params));
}
}
My solution may be looks not so glad, but it's works at least:
You may organize your routs in way
yoursite.com/term1Name/**:param1**/term2Name/**:param2**/term3Name/**:param3**
To make it's clear, you may do your routes seems like REST routes. For example I'm want to go to a list of a services:
www.yoursite.com/servises/
Go to the one of the services:
www.yoursite.com/servise/:id
And if I'm want to see some of the service details, I'll do:
www.yoursite.com/servise/:id/details
and so
www.yoursite.com/servise/:id/detail/:id