我想确保只在我使用设备(iOs,Android ...)时启动inappbrowser,但如果我在浏览器(本地开发模式或只是带有gulp构建的Web应用程序),我想要链接到目标="_空白"的页面.
我正在尝试将Ionic 2代码重用为Web App.所以当我构建应用程序时,它也可以在浏览器桌面上运行.所以platform.ready()对我来说还不够.因为我需要知道用户是否在桌面浏览器上,我可以做一些不同的事情.
ngrx/Store和reducer都是新手.基本上,我有这个减速器:
import {StoreData, INITIAL_STORE_DATA} from "../store-data";
import {Action} from "@ngrx/store";
import {
USER_THREADS_LOADED_ACTION, UserThreadsLoadedAction, SEND_NEW_MESSAGE_ACTION,
SendNewMessageAction
} from "../actions";
import * as _ from "lodash";
import {Message} from "../../shared-vh/model/message";
import {ThreadsService} from "../../shared-vh/services/threads.service";
export function storeData(state: StoreData = INITIAL_STORE_DATA, action: Action): StoreData {
switch (action.type) {
case SEND_NEW_MESSAGE_ACTION:
return handleSendNewMessageAction(state, action);
default:
return state
}
}
function handleSendNewMessageAction(state:StoreData, action:SendNewMessageAction): StoreData {
const newStoreData = _.cloneDeep(state);
const currentThread = newStoreData.threads[action.payload.threadId];
const newMessage: Message = {
text: action.payload.text,
threadId: action.payload.threadId,
timestamp: new …Run Code Online (Sandbox Code Playgroud) 因此,每当我从Firebase注销时,我都会加入
Error: permission_denied: Client doesn't have permission to access the desired data.
Run Code Online (Sandbox Code Playgroud)
我理解这是因为登录会话终止,我的一些对象无法再访问firebase数据.但是如何在注销前断开此对象?
对于我的Ionic View中的注销按钮,它只需调用firebase服务:
function logout() {
auth.$unauth();
getCurrentUser();
};
function getCurrentUser() {
var authData = auth.$getAuth();
if (authData) {
$rootScope.userId = authData.uid;
$rootScope.currentUser = $firebaseObject(authRef.child("users").child(authData.uid));
return $rootScope.currentUser;
} else {
console.log("User is not login!");
$rootScope.userId = null;
$location.path("/auth/signin");
if ($rootScope.currentUser) {
$rootScope.currentUser.$destroy();
}
}
};
Run Code Online (Sandbox Code Playgroud)
所以我在那里销毁$ rootScope.currentUser.我为配置文件页面使用相同的getCurrentUser.因此错误没有以这种方式出现.但是在其他视图中,我有另一个$ firebaseArray,还有另一个Ref.on("child_added",函数(snap)与$ firebaseObject相同.当我查看配置文件页面时,此页面至少有3个firebase连接,当我退出时,我有3个permission_denied错误(注销按钮在用户个人资料页面上).
我的问题是,在注销之前如何断开此firebase连接?有没有办法断开所有firebase连接 - 无论是AngularFire还是常规的Firebase?所以我可以注销而不用担心哪个firebase连接没有关闭呢?此外,由于Logout按钮位于Profile范围内,而其他连接位于不同的范围内,因此我不知道如何关闭甚至在配置文件范围内的连接...
所以我有这样的数据:
pushNotifications {
-K - RwEgd541PIGNOXXUH: {
message: "Xiaoyu Hugh Hou bid at $900 on your task: New P..."
notifyId: "facebook:10100683829966199"
relatedTask: "-Jzl8XKaxGCv19nIOChm"
timestamp: 1443594566599
} - K - RwpcBlQa04VJT4Bwm: {
message: "Sam Feldt bid at $1100 on your task: New Post g..."
notifyId: "google:1043268349966197"
relatedTask: "-Jzl8XKaxGCv19nIOChm"
timestamp: 1443594721963
} - K - RwuM3 - 0 G0q9I96WHg: {
message: "Sam Feldt bid at $600 on your task: NO Firebase..."
notifyId: "facebook:10100683829966199"
relatedTask: "-JzTSk2TIlO46oVqJ1Nn"
timestamp: 1443594741347
}
}
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我需要将下面的最新通知发送到某个"notifyId".这是代码:
ref.child('pushNotifications')
.orderByChild("notifyId") …Run Code Online (Sandbox Code Playgroud) 情况:我正在使用FirebaseObjectObservable来填充我的Ionic 2(rc0)模板.模板代码:
<p>{{(course | async)?.description}}</p>
<button ion-button dark full large (click)="openDeckOnBrowser(course.deckUrl)">
<ion-icon name='cloud-download'></ion-icon>
<div>View Deck</div>
</button>
Run Code Online (Sandbox Code Playgroud)
TS文件是
this.course = this.af.database.object('/bbwLocations/courses/' + courseId);
Run Code Online (Sandbox Code Playgroud)
this.course是Firebase Object Observable.问题是,这部分不起作用:( click)="openDeckOnBrowser(course.deckUrl).由于course.deckUrl为空.我无法将值传递给函数.
到目前为止,我发现只能使用hacky方式:
<button id="{{(course | async)?.deckUrl}}" ion-button dark full large (click)="openDeckOnBrowser($event)">
<ion-icon name='cloud-download'></ion-icon>
<div id="{{(course | async)?.deckUrl}}">View Deck</div>
</button>
Run Code Online (Sandbox Code Playgroud)
并在点击事件:
openDeckOnBrowser(event):void {
console.log(event);
let target = event.target || event.srcElement || event.currentTarget;
let idAttr = target.attributes.id;
let url = idAttr.nodeValue;
console.log (url);
}
Run Code Online (Sandbox Code Playgroud)
但任何官方和更容易的方法来解决这个问题?
我是Observable样式编程的新手.我有一个问题:我希望在组件之间跨应用程序共享用户信息 - 我使用BehaviorSubject来共享此信息.这是通过将BehaviorSubject共享为AuthInfo来启发的.如果我可以在我的应用程序组件中共享包含uid的AuthInfo,为什么我可以使用它来共享我的用户对象数据?
问题是,用户对象,我是从Firebase获得的.所以它是一个Observable,我不知道如何将它分配给一个行为主题.所以这是我尝试的代码:
@Injectable()
export class AuthService {
static UNKNOWN_USER = new AuthInfo(null);
static EMPTY_USER = new User(null, null, null, null);
authInfo$: BehaviorSubject<AuthInfo> = new BehaviorSubject<AuthInfo>(AuthService.UNKNOWN_USER);
userInfo$: BehaviorSubject<User> = new BehaviorSubject<User>(AuthService.EMPTY_USER);
constructor(private auth: FirebaseAuth, private db:AngularFireDatabase, @Inject(FirebaseRef) fb) {
//firebase way to see if user is login or not
this.auth.subscribe(user => {
if (user) {
const authInfo = new AuthInfo(user.uid);
this.authInfo$.next(authInfo);
//This is the part I do not know how to do
[OPTION 1]: this.userInfo$.next(findUserByuid(user.uid)) ?? - error
[OPTION …Run Code Online (Sandbox Code Playgroud) 我用Firebase构建了我的应用程序,一切运行良好.但现在我需要向Uber风格的用户收费(使用Stripe Connect或市场解决方案).Stripe要求服务器设置为CHARGE用户.Angular只能生成Stripe标记.我可以使用Firebase(或Firebase队列)来执行CHARGE用户部分,因此我不需要创建新的nodejs服务器来插入几行条带代码吗?如果是这样,谁能告诉我如何做到这一点或例子?谢谢!
这里是Angular2的新手,想知道如何在阵列模式上执行此异步请求(不太确定模式名称).
因此,假设我使用Angular2 Http来获取videoId每个返回项目中包含的YouTube播放列表.然后我需要循环浏览此项目videoId并向YouTube发送另一个请求以获取个人视频信息.这可以是另一个常见的HTTP请求,获取列表然后遍历列表并获取每个单独项目的详细信息.
let url = [YouTube API V3 list url]
let detailUrl = 'https://www.googleapis.com/youtube/v3/videos?part=contentDetails,statistics';
this.http.get(url)
.map(res => res.json())
.subscribe(data => {
let newArray = data.items.map(entry => {
let videoUrl = detailUrl + '&id=' + entry.id.videoId +
'&key=' + this.googleToken;
this.http.get(videoUrl)
.map(videoRes => videoRes.json())
.subscribe(videoData => {
console.log(videoData);
//Here how to I join videoData into each item inside of data.items.
});
});
});
Run Code Online (Sandbox Code Playgroud)
所以上面的代码确实有效.但我仍然有这两个问题:
我如何加入videoData回data.items,并确保正确的物品内部的data.items与正确的加入videoData(在videoData正在使用 …
情况:我正在使用FirebaseObjectObservable来填充我的Ionic 2(rc0)模板.模板代码:
<ion-card-content>
<p>{{(course | async)?.description}}</p>
<br>
<h2>Learning Objectives</h2>
<ul>
<li *ngFor = "let objective of (course | async)?.objectives">{{objective.text}}</li>
</ul>
<h2>Takeaway</h2>
<ul>
<li *ngFor = "let takeaway of (course | async)?.takeaways">{{takeaway.text}}</li>
</ul>
</ion-card-content>
Run Code Online (Sandbox Code Playgroud)
TS代码:
this.course = this.af.database.object('/bbwLocations/courses/' + courseId);
Run Code Online (Sandbox Code Playgroud)
this.course是Firebase Object Observable.一切正常!但每当我进入模板时,都会出现空白无数据.然后所有的数据跳出来!非常友好的UX.所以我想使用某种预加载策略.但由于这里没有TS逻辑.使用异步管道在模板级别控制所有内容.在这种情况下如何添加加载?
我需要使用Google OAuth签署用户,然后在Ionic 2应用程序中获取用户YouTube频道信息(只读).由于Google在2017年4月停止了inappbrowser auth流程,我唯一的选择是使用cordova-plugin-googleplus来实现这一点(http://blog.ionic.io/google-oauth-changes/).
但是,在使用cordova-plugin-googleplus登录后,在iOS中我可以在响应中获取accessToken而不是Android.所以我需要一个额外的步骤来获取accessToken,这样我就可以调用Google YouTube API 3来获取没有服务器的用户YouTube信息.怎么做?到目前为止,这是我的代码:
googlePlusLogin()
{
if(this.platform.is('cordova')){
//user is using it as an mobile app
return this.platform.ready().then(() => {
// In-App solution
return new Promise((resolve, reject) => {
return GooglePlus.login({
'scopes':'email https://www.googleapis.com/auth/youtube.readonly',
'webClientId' : [web client id],
'offline': true,
})
.then((userData) => {
console.log("userData " + JSON.stringify(userData));
var provider = firebase.auth.GoogleAuthProvider.credential(userData.idToken);
let token: any;
let fullData:any;
token = userData.accessToken;
let headers = new Headers();
let googleAPI = "https://www.googleapis.com/youtube/v3/channels?part=brandingSettings%2C+snippet%2C+id%2C+statistics&mine=true";
headers.append('Authorization', 'Bearer ' + token);
headers.append('Content-Type', …Run Code Online (Sandbox Code Playgroud) firebase google-oauth firebase-authentication ionic2 angular
angular ×6
firebase ×4
ionic2 ×4
observable ×4
angularfire2 ×2
angularjs ×2
angularfire ×1
asynchronous ×1
cordova ×1
google-oauth ×1
ngrx ×1
redux ×1
rxjs ×1