I am trying to develop 2 pages:
Page 1: Normal Login Page login.html
Page 2: Home Page home.html
I am using AngularJS to code the scripts in these pages.
I have to transfer some data between these two pages. So i decided to use cookies (I tried to use Services but i didn't know how to write the same service for 2 separate files).
In the Login page i saved the cookies as follow :
var resultObj = {'loginid',result};
$cookies.dotobject = resultObj;
window.location = 'Home.html';
I checked that this cookie is saved correctly (Console.log(resultObj))
However when i open the home page i try to read this cookie using:
var result = $cookies.dotobject;
console.log(result) //To check if it worked
But it didn't, i got undefined.
My question is can I use $cookies in this case ? And why does it disappear ?
If cookies are not useful in this case how to use a service between 2 different pages containing 2 different controllers ?
Excuse me if this questions aren't from a good quality since i am still learning these concepts.
EDIT
I tried to write in the same document :
console.log(result);
$cookies.put('loginid',result);
var loginida = $cookies.get('loginid');
console.log(loginida);
But the $cookies.get does not work ; It gives also undefined . Any ideas ?
https://embed.plnkr.co/oCd2WrzJjFtvgsGdHrdV3b/
Hello , I created Login page and Register page. But I need to add an additional functionality of confirm password. I am pretty confused in handling this with my controllers.
can anyone help me in validation part.
When I give Ng-match or directives , it is not compatible with my existing controller. Either it states Registration successful in case of wrong password or else my view is just empty in browser.
Use following ng-match directive
http://ngmodules.org/modules/ng-match
plnkr.co/edit/LRXKpql1AxmGNcTWifGS?p=preview
I solved the issue you faced with confirmPassword. I'm just
saying where you made the mistake
1)password name in ng-modal and name in "required data-password-verify" at confirm password should match when you compare two passwords.
2)Please have a look at console first,then you understand where you did a mistake.Console clearly saying two issues i.e app is not defined at passwordVerify.js and User service not defined.
3)I changed passwordVerfiy directive to register controller and I commented userservice wherever i find.Because I have not seen anywhere you are using Userservice class.Both the files(user.service and user.service,localstorage) are empty
I would be more happy if my code resolve your problem.
Thank you
I am new to Angular.js and i am facing problem in maintaining the JSON feed values in the view.
I am using different routers and when i launch the app it loads the home.html which in turns calls the homeCtrl and make an HTTP call and binds the data using ng-repeat ( in home.html ). If user clicks on the list item to brings them to detail.html ( kind of detail page ).
Now the problem i face is , on the detail page when user tabs the back button - the app goes to home.html and the homeCtrl again hits the webservice and bind the whole data once again. Which i feel is unwanted as the JSON datas was already collected on the 1st time page load itself.
How can i preserve the old data when user move back forth between different views so i no need to hit same call over and over.
Thanks and sorry if its really basic stuff.
How can i preserve the old data when user move back forth between
different views so i no need to hit same call over and over.
If you use the $http service to make the requests use the cache: true option to use the default angular cache as explained in the docs: https://docs.angularjs.org/api/ng/service/$http#caching
Here an example:
$http.get(url, { cache: true}).then(...);
You can also define your custom cache object through the $cacheFactory service: https://docs.angularjs.org/api/ng/service/$cacheFactory
If you want some more complete with expiration, size limit and other cool stuff try angular-cache: https://github.com/jmdobry/angular-cache
Hi I think that you need is create a factory or service;so in this way the controllers shared data between them.
Here's an example
I'm trying to use this attribute on methods in the web API for a custom module:
[DnnModuleAuthorize(AccessLevel = DotNetNuke.Security.SecurityAccessLevel.Edit)]
but no matter what SecurityAccessLevel I set, I always get a 401 unauthorized response.
I was able to make the code work by adding:
[AllowAnonymous]
on the method, and adding:
if (!ModulePermissionController.CanEditModuleContent(this.ActiveModule))
return Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "You do not have permission to access this content.");
to the beginning of my method, but it seems like this is a workaround that I really shouldn't need because it's exactly what that attribute is there for. I'm running DNN 7.2.1.
Anyone have any idea where I'm going wrong with the attribute?
Turns out it was actually related to the anti-forgery token. I'm using Angular so I'm setting my headers manually in my Angular service rather than using the built-in ServicesFramework setModuleHeaders method and was only setting the TabId and ModuleId. I didn't think the [AllowAnonymous] attribute would override the anti-forgery stuff but it looks like it definitely does (which is good to know).
Full solution for those doing the same:
var baseUrl = sf.getServiceRoot('[yourmodulename]') + '[controller]';
var config = {
headers: {
'ModuleId': sf.getModuleId(),
'TabId': sf.getTabId(),
'RequestVerificationToken': sf.getAntiForgeryValue()
}
};
Do you have the SupportedModules attribute applied to your controller (or action method)? If so, I'd guess there's a mismatch between the name you're passing in there and the real name in DNN (you should be passing in the desktop module name). Try removing that attribute and seeing if it helps.
The same process that sets ActiveModule and the current user (and would thus make your check in the action method work) should be responsible for implementing the DnnModuleAuthorize attribute's check. So, that's definitely perplexing. Maybe that changed, and if you just pass ModuleId but not TabId in the headers, then it sets ActiveModule, but won't authenticate?
Have you looked at the traffic in Fiddler and made sure that the ModuleId and TabId headers are being sent correctly? Does being logged in as a super-user (i.e. host-level user) affect any of the auth checks (if so, perhaps the URL isn't being constructed properly, and DNN is identifying the wrong portal)?
When you initialize the ServicesFramework, make sure you do it inside a document.ready function.
var self = {};
jQuery(document).ready(function ($) {
self.sf = $.ServicesFramework(<%=ModuleID %>);
});
More info: www.dnnsoftware.com/forums/threadid/507753/scope/posts/services-framework-problems
My AngularJS application needs to have access to the user's LinkedIn profile. In order to do that I need to redirect the user to a LinkedIn URL which contains a callback redirect_uri parameter which will tell LinkedIn to redirect the user back to my webapp and include a "code" query param in the URL. It's a traditional Oauth 2.0 flow.
Everything works great except that LinkedIn redirects the user back to the following URL:
http://localhost:8080/?code=XXX&state=YYY#/users/123/providers/LinkedIn/social-sites
I would like to remove ?code=XXX&state=YYY from the URL in order to make it clean. The user does not need to see the query parameters I received from LinkedIn redirect.
I tried $location.absUrl($location.path() + $location.hash()).replace(), but it keep the query params in the URL.
I am also unable to extract the query parameters, e.g. "code", using ($location.search()).code.
It seems like having ? before # in the URL above is tricking Angular.
I use
$location.search('key', null)
As this not only deletes my key but removes it from the visibility on the URL.
I ended up getting the answer from AngularJS forum. See this thread for details
The link is to a Google Groups thread, which is difficult to read and doesn't provide a clear answer. To remove URL parameters use
$location.url($location.path());
To remove ALL query parameters, do:
$location.search({});
To remove ONE particular query parameter, do:
$location.search('myQueryParam', null);
To clear an item delete it and call $$compose
if ($location.$$search.yourKey) {
delete $location.$$search.yourKey;
$location.$$compose();
}
derived from angularjs source : https://github.com/angular/angular.js/blob/c77b2bcca36cf199478b8fb651972a1f650f646b/src/ng/location.js#L419-L443
You can delete a specific query parameter by using:
delete $location.$$search.nameOfParameter;
Or you can clear all the query params by setting search to an empty object:
$location.$$search = {};
At the time of writing, and as previously mentioned by #Bosh, html5mode must be true in order to be able to set $location.search() and have it be reflected back into the window’s visual URL.
See https://github.com/angular/angular.js/issues/1521 for more info.
But if html5mode is true you can easily clear the URL’s query string with:
$location.search('');
or
$location.search({});
This will also alter the window’s visual URL.
(Tested in AngularJS version 1.3.0-rc.1 with html5Mode(true).)
Need to make it work when html5mode = false?
All of the other answers work only when Angular's html5mode is true. If you're working outside of html5mode, then $location refers only to the "fake" location that lives in your hash -- and so $location.search can't see/edit/fix the actual page's search params.
Here's a workaround, to be inserted in the HTML of the page before angular loads:
<script>
if (window.location.search.match("code=")){
var newHash = "/after-auth" + window.location.search;
if (window.history.replaceState){
window.history.replaceState( {}, "", window.location.toString().replace(window.location.search, ""));
}
window.location.hash = newHash;
}
</script>
If you want to move to another URL and clear the query parameters just use:
$location.path('/my/path').search({});
Just use
$location.url();
Instead of
$location.path();
If you are using routes parameters just clear $routeParams
$routeParams= null;
How about just setting the location hash to null
$location.hash(null);
if you process the parameters immediately and then move to the next page, you can put a question mark on the end of the new location.
for example, if you would have done
$location.path('/nextPage');
you can do this instead:
$location.path('/nextPage?');
I've tried the above answers but could not get them to work. The only code that worked for me was $window.location.search = ''
I can replace all query parameters with this single line: $location.search({});
Easy to understand and easy way to clear them out.
The accepted answer worked for me, but I needed to dig a little deeper to fix the problems with the back button.
What I noticed is that if I link to a page using <a ui-sref="page({x: 1})">, then remove the query string using $location.search('x', null), I don't get an extra entry in my browser history, so the back button takes me back to where I started. Although I feel like this is wrong because I don't think that Angular should automatically remove this history entry for me, this is actually the desired behaviour for my particular use-case.
The problem is that if I link to the page using <a href="/page/?x=1"> instead, then remove the query string in the same way, I do get an extra entry in my browser history, so I have to click the back button twice to get back to where I started. This is inconsistent behaviour, but actually this seems more correct.
I can easily fix the problem with href links by using $location.search('x', null).replace(), but then this breaks the page when you land on it via a ui-sref link, so this is no good.
After a lot of fiddling around, this is the fix I came up with:
In my app's run function I added this:
$rootScope.$on('$locationChangeSuccess', function () {
$rootScope.locationPath = $location.path();
});
Then I use this code to remove the query string parameter:
$location.search('x', null);
if ($location.path() === $rootScope.locationPath) {
$location.replace();
}