小编Div*_*ero的帖子

当预期页面重新加载时,AngularJS路由劫持非基本URL

我正在构建一个不在根位置的AngularJS应用程序domain.tld/blog.我有/blog基础上的所有东西的路由设置.我在页面的头部包含了基本标记<base href="/blog">.html5Mode设置为true.在应用程序内,一切都按预期工作.但是,当我单击基本位置之外的非角度URL时,不会加载页面.似乎这个位置被otherwise路由器中的功能捕获:

ROUTER.otherwise({
  redirectTo : '/blog'
});
Run Code Online (Sandbox Code Playgroud)

所以当我点击任何网址时,即domain.tld/somewhere-else它会重定向到domain.tld/blog.显然,这是您所期望的:对于路由器中找不到的每个URL,将其重定向到"主页".在我的应用程序中,这不是理想的行为.所有不在路由器中的网址都应被视为普通网址,并将网页重新加载到该网址.

所以我需要的是这样的:

ROUTER.otherwise(
     window.location = theRequestedUrl;
);
Run Code Online (Sandbox Code Playgroud)

这显然不起作用.但不知何故,我需要进入路由器的其他部分并告诉它重定向到页面重新加载页面.

以下问题是相关的:角度路由奇怪的事情发生

以下jsFiddle演示了这个问题(感谢@rdjs!)http://fiddle.jshell.net/43tub/6/show/light/.点击/outside链接应该做整页刷新...

routing angularjs

9
推荐指数
2
解决办法
5083
查看次数

Chrome扩展弹出窗口中的Firebase身份验证

我正在尝试在Chrome扩展程序中使用身份验证(电子邮件/密码).如果我将我的身份验证代码放在后台脚本中,我似乎工作正常.但是我似乎无法将其作为浏览器动作脚本工作.

我使用以下代码作为我的扩展的基础:https://github.com/firebase/firebase-chrome-extension

我将browser_action.js更改为:

Firebase.enableLogging(true);
var f = new Firebase('https://myapp.firebaseio.com/');

f.authWithPassword({    
    email    : "a@b.cd",
    password : "1234"
}, function(error, authData) {
    if (error) {
        alert("Login Failed!", error);
} else {
    alert("Authenticated successfully with payload:", authData);
}
});
Run Code Online (Sandbox Code Playgroud)

我保持现有的browser_action.html不变:

<!doctype html>


<style type="text/css">
    #mainPopup {
        padding: 10px;
        height: 200px;
        width: 400px;
        font-family: Helvetica, Ubuntu, Arial, sans-serif;
    }
    h1 {
        font-size: 2em;
    }
</style>

<div id="mainPopup">
<h1>Firebase test!</h1>
<p>Clicks: <span id="contents"></span></p>
</div>

<script type="text/javascript" src="https://cdn.firebase.com/v0/firebase.js"></script>
<script src="browser_action.js"></script>
Run Code Online (Sandbox Code Playgroud)

当我加载扩展并单击图标时,它在控制台中给出以下错误:

Uncaught TypeError: …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome-extension firebase firebase-authentication

7
推荐指数
2
解决办法
2324
查看次数

Angular2中的嵌套Observable使用AngularFire2不在视图中渲染

我正在构建一个使用Firebase和AngularFire2(目前处于alpha版)的实验性(Ionic 2)应用程序.为此,我将遵循Aaron Saunders的教程作为基础:

http://www.clearlyinnovative.com/integrating-firebase-with-angularfire2-into-angular2-ionic2-part-2 https://github.com/aaronksaunders/ionic2-angularfire-sample

以下是我的home.ts和我的home.html.

this.projects = af.list('/items').map( (items) => {
    return items.map( item => {
        item.meta = af.object(`/item_meta/${item.$key}`)
        return item
    })
})
Run Code Online (Sandbox Code Playgroud)

以下演示文稿演示了AngularFire2嵌套Observables返回的方法:https://youtu.be/ngnSOTSS8Q8?t = 1h6m37s

这是我的观点:

<ion-card *ngFor="#item of items | async">
    <ion-card-header>
        {{item.name}}
    </ion-card-header>
    <ion-card-content>
        {{item.description}}
        <br>

        {{item.meta.stockPrice | async}}

    </ion-card-content>
</ion-card>
Run Code Online (Sandbox Code Playgroud)

与我所遵循的演示中的示例的主要区别在于,我在'list/array'Observable中嵌套了一个'对象'Observable.相反,他们在列表中添加一个列表.这样做的结果是我试图直接在我的视图中渲染{{item.meta.stockPrice}}而不是嵌套ngFor.

这就是我的数据:

{
    "items":
        {
            "item1":{
                "name": "Item 1",
                "description": "1234"
            },
            "item2":{
                "name": "Item 2",
                "description": "abcd"
            }
        }
    "items_meta"{
        "item1":{
            "stockPrice": 1234,
            "moarData": "derp"
        },
        "item2":{
            "stockPrice": 386,
            "moarData": "lolz"
        } …
Run Code Online (Sandbox Code Playgroud)

observable angularfire ionic2 angular

6
推荐指数
1
解决办法
5549
查看次数

AngularJS中ng-repeat内的动态过滤器

对于我的AngularJS应用程序,我在ng-repeat中有一个ng-repeat,如下所示:

HTML:

<div ng-app="myApp">
    <div ng-controller="myController">
        <h2>working filter</h2>
        <div ng-repeat="category in categories">
            <h3>{{category}}</h3>
            <div ng-repeat="item in items | filter:{price.red: 0} ">{{item.name}}</div>
    </div>

        <h2>broken filter</h2>
        <div ng-repeat="category in categories">
            <h3>{{category}}</h3>
            <!-- price[category] should be red, blue, yellow, depending on the category in the ng-repeat -->
            <!-- price[category] should be bigger then 0 (or not zero, negative values will not occur) -->
            <div ng-repeat="item in items | filter:{price[category]: 0} ">{{item.name}}</div>
        </div>

    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

使用Javascript:

var myApp = angular.module('myApp', []);

myApp.controller('myController', function ($scope) …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-ng-repeat angularjs-filter

5
推荐指数
1
解决办法
2万
查看次数

从GIT更新后挂钩执行PHP

我在我的服务器上使用GIT,并且每次更新我的存储库时,我都试图获取一个PHP文件.我正在尝试使用我的更新后挂钩来实现这一目标.

这是我试过的代码:

#!/bin/sh

echo
echo "**** Pulling changes into Prime [Hub's post-update hook]"
echo

cd $HOME/www || exit
unset GIT_DIR
git pull hub master

exec git-update-server-info

php /path/to/directory/file.php
Run Code Online (Sandbox Code Playgroud)

我似乎无法让PHP执行.任何人都可以对此发光吗?

php git hook gitosis githooks

3
推荐指数
1
解决办法
1660
查看次数