The problem here is that i need to somehow get the information of the user when he logs in. So what is happening is that when he register all goes fine he goes to another page and it says "Welcome" + username And it does it correctly! But when i do it with the login page the username becomes undefined. Im preety sure i like somehow need to store my data in a factory but stumbled on how to. Thats what i think but may not be true. Anways...
Here is the plunker: http://plnkr.co/edit/qB3Gkeq5ji1YQyy0kpGH
Thank you so much for your help!
Use FirebaseAuth
in your controller you're using firebase array not Auth. This is an extract of the correct way to auth with firebase.
// define our app and dependencies (remember to include firebase!)
var app = angular.module("sampleApp", ["firebase"]);
// inject $firebaseAuth into our controller
app.controller("SampleCtrl", ["$scope", "$firebaseAuth",
function($scope, $firebaseAuth) {
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
var auth = $firebaseAuth(ref);
}
]);
Here is a link to the Docs with the exact tutorial. I would advise following it all the way through to learn firebase.
Related
Here i have soo many factory Pages assiging Urls in Every page is difficulty for me could you please Help me how can i put all urls at One Place And access in all page Like
app.factory('Fac1',function($http){
var hostUrl:'http:loaclhost:4200'
}
and second factory is
app.factory('Fac2',function($http){
var hostUrl:'http:loaclhost:4200'
}
soo on
Please Help me how can i put This HostUrl in one Place
you can use constant variable for your url's.
var app = angular.module('myApp',[]);
in another file you can add all your urls
app.constant("urlConstant", {
Url_Base: 'http://localhost:4200/',
Url_EmployeeList: 'getEmployeeList'
});
now inject this urlConstant to all your factory just like below
app.factory('Fac1',['$http','urlConstant',function($http,urlConstant){
var hostUrl: urlConstant.Url_Base;
var getEmployeeListurl: urlConstant.Url_Base + urlConstant.Url_EmployeeList;
}]);
I am working on app where I have 2 subdirectories inside public namely admin and core. admin is for admin users where we need to login and add,Edit,delete posts while in core we have pages which a public user or visitors can see. Now what I want is that I have a CRUD functionality implement in admin. I have controller, routes and services. but what I don't know is that how can I display the data in core views for public users I needs steps to to re-use some of the code from admin and retrieve and display data in core views.
Here is a link to the directory structure: http://take.ms/LdaWk
Imagine the following structure...
app
|- admin
|- api
|- core
The api defines your CRUD functions. For example, in Slim PHP something like
$api = new \Slim\Slim();
// audio/video
$api->get('/av', 'getAVs');
$api->get('/av/:id', 'getAV');
$api->post('/add/av', 'addAV');
$api->put('/update/av/:id', 'updateAV');
$api->delete('/delete/av/:id', 'deleteAV');
// define functions that handle http requests above...
Now in admin, you can call the api in angularjs using $http. For example calling the resource POST /add/av
var admin = angular.module('adminApp', ['ngRoute']);
admin.controller('addAvCtrl', function($scope, $http, MsgService){
MsgService.set('');
// process the form
$scope.submit = function() {
$http.post('../api/add/av', $scope.formData)
.success(function() {
MsgService.set('Success!');
});
};
$scope.message = MsgService.get();
});
In core you can use the same api to display data. For example calling the resource GET /av/:id
var core= angular.module('coreApp', ['ngRoute']);
core.controller('mediaCtrl', function($scope, $http, $routeParams){
$http.get('../api/av/' + $routeParams.id)
.success(function(response) {
$scope.media_detail = response;
});
});
Obviously, this is a rough outline. You would need to fill out the code, but it displays the principle.
You can implement a component base structure, something like:
Components
TestComponent
AddTestComoonent
EditTestComponent
ListTestComponent
That each component has own module and router. and whenever you want you can just inject the module and use it
when I navigate to URL of my app:
http://localhost/RealSuiteApps/RealHelp/-1/Inbox/Detail?wonum=XXX
I want to get the value of wonum
Below is the constructor of my controller, I tried to use $location service as defined in angular documentation, but it doesnt work, what is the problem?
constructor(private dataService: DataService, private $location) {
var params = $location.search();
var wonum = params.wonum;
this.getWorkOrderDetail(wonum);
}
Please note, the URL above is a link from one page to another, but it is not angular routing.
UPDATE
Adding # after Detail and before the question mark solves the issue
http://localhost/RealSuiteApps/RealHelp/-1/Inbox/Detail#/?wonum=BCB18405240
I suspect if its an angular application. Because an angular application will always append a # to the url and that is how angular maintains state of url's. $location.search() method will yield results only if the url is hash based.
I'm trying to make a login session persist upon a page refresh but I'm not being successful in this matter. I took a look at this solution found here which uses the $firebaseSimpleLogin service to maintain a login session.
From that solution all I've done is basically deleted his wrapper that points to the Firebase instance, replaced it with my own var ref and put it as an argument of the $firebaseSimpleLogin. I also implemented array notation since I've done it with my controllers as well.
However, this function isn't even being executed because when I run the code it throws this error:
Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.3.10/$injector/unpr?p0=%24firebaseSimpleLoginProvider%20%3C-%20%24firebaseSimpleLogin
Does anyone know why I'm getting this? I can't see anything wrong with my injections like the error is telling me.
var pieShopApp = angular.module('pieShopApp', ['ngRoute', 'ngAnimate', 'firebase']);
var ref = new Firebase ('https://pie-shop.firebaseio.com/users');
pieShopApp.run(['$rootScope', '$location', '$firebaseSimpleLogin', function($rootScope, $location, $firebaseSimpleLogin) {
$rootScope.auth = $firebaseSimpleLogin(ref);
$rootScope.auth.$getCurrentUser().then(function(user) {
if (user) {
$rootScope.currentUser = user;
console.log($rootScope.currentUser);
}
else {
$location.path('/pies/login');
}
});
}]);
So I'm trying to use Facebook login with angularfire 0.5 and I'm having some issues.
I've simply copy-pasted the documentation code from the angularfire website but it doesn't seem to trigger a connection to Facebook.
This is my controller code:
.controller('MainCtrl', function ($scope, $firebase, $firebaseAuth) {
var ref = new Firebase('https://xlib.firebaseio.com/lunsjfeed');
$scope.auth = $firebaseAuth(ref);
});
This is the code from the view:
Login
I get no errors in the console. I can fetch and write data to firebase without any problems, but I can't the login api to work.