我现在正在将基于Angularjs的Web应用程序中的幻像集成.
这美好的文章说,我应该调用$locationProvider.hashPrefix()方法来设置前缀"!" 来自SEO的原因(允许抓取工具拦截_escaped_fragmentURL 的组件).
问题是我之前没有,我的一些URL看起来如下:
#/home.
我可能有一种方法可以植入这个'!' 在APP的配置功能中以编程方式将URL填入URL(如果它尚未存在),而是必须手动编辑大量标记.
我使用以下两个过滤器的组合首先从显而易见的原因(防止攻击)中删除用户输入的所有HTML,然后替换
标签中的所有\n .
<span data-ng-bind-html-unsafe="model.userInput | noHTML | newlines"></span>
Run Code Online (Sandbox Code Playgroud)
filters.filter('newlines', function () {
return function(text) {
console.log(text)
return text.replace(/\n/g, '<br/>');
}
})
filters.filter('noHTML', function () {
return function(text) {
return Boolean(text) ? text
.replace(/&/g, '&')
.replace(/>/g, '>')
.replace(/</g, '<') : '';
}
});
Run Code Online (Sandbox Code Playgroud)
问题是在角度1.2.2中不推荐使用bind-html-unsafe,并且必须使用$ sce(严格上下文转义)来"信任html",它返回一个函数,我显然无法应用这些过滤器.
新代码:
ctrls.controllers('someCtrl', function($scope, $sce){
$scope.trusterInput = $sce.trustAsHtml($scope.userInput);
});
Run Code Online (Sandbox Code Playgroud)
错误:
TypeError: Object [object Object] has no method 'replace'
at Scope.<anonymous> (http://localhost:8000/js/filters.js:20:20)
at fnInvoke (http://code.angularjs.org/1.2.2/angular.js:9756:21)
at OPERATORS.| (http://code.angularjs.org/1.2.2/angular.js:9271:59)
at extend.constant (http://code.angularjs.org/1.2.2/angular.js:9701:14)
at OPERATORS.| (http://code.angularjs.org/1.2.2/angular.js:9271:74)
at extend.constant (http://code.angularjs.org/1.2.2/angular.js:9701:14) …
我的用例:尝试发布PUT请求,将帖子从小组的一般性讨论转移到工作讨论.
要发出该请求,您需要一个典型的丑陋的LinkedIn XML以及URL中的帖子ID.
问题是post id仅作为接收的位置标题的一部分出现,它是从POST请求(而不是在响应主体)获得的.
除使用数据包嗅探外的任何解决方案?
2011年的这个OPEN错误描述了同样的问题.
我需要将用户配置文件和他的首选项存储在localStorage对象\ cookies中,以便它们可以从web-app和chrome扩展(基本上是同一产品的一部分)访问(可读)和写入).
问题是xauth.org已关闭,使用该库所需的服务器页面也是如此.
任何替代品
我有以下测试:
it('should load productGroups into the scope', function(){
scope._section = 'modifiers';
scope.userData = {method: 'manual'};
scope.$digest();
timeout.flush();//causes the error
expect(scope.productGroups).toEqual(productGroupService.getProductGroups());
});
Run Code Online (Sandbox Code Playgroud)
现在,由于我在同步 cookie 中存储的数据时遇到了一些问题,我尝试测试的操作发生在 0 超时内。
现在,没有标记的行,测试运行找到,除了没有获得预期的结果。使用标记线,我收到以下错误:
Error: Unexpected request: GET views/main.html
No more request expected
at $httpBackend (/home/oleg/dev/vita-webapp-new/bower_components/angular-mocks/angular-mocks.js:1178:9)
at sendReq (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:8180:9)
at $http.serverRequest (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:7921:16)
at wrappedCallback (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:11319:81)
at wrappedCallback (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:11319:81)
at /home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:11405:26
at Scope.$eval (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12412:28)
at Scope.$digest (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12224:31)
at Scope.$apply (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12516:24)
at Object.fn (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:14023:36)
Process finished with exit code 0
Run Code Online (Sandbox Code Playgroud)
main.html,显然是这个控制器的视图,尝试使用以下代码将其放置在 templateCache 中,但没有帮助:
$templateCache.put('views/main.html', $templateCache.get('app/views/views/main.html'));
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激。
我正在使用pcntl来加速一个相当流行的CLI php脚本,该脚本主要由一个类组成,它负责在我的应用程序上发送所有自动电子邮件.
我的目标如下:我想在foreach循环中将每个进程分配给某个任务,我使用的实现是下面代码示例中显示的实现.
问题是,一旦你分叉一个进程,它就会异步执行,并获得父进程堆栈的副本. 在我的情况下,发生的事情是一个任务只执行几次, 我的问题是我如何设计这个脚本更聪明,以避免这种行为?
码:
/**
@description this is the main procedure of this class, it iteratates over the relevant tasks and sends the emails using the SendGrid wrapper class
@see SendGridWrapper
@return void
*/
public function execute(){
if(!isset($this->tasks)){
throw new exception("Please call getRelevantTasks() prior to trying to execute anything");
}
$proccesses = array();
foreach($this->tasks as $myTask){
$pid = pcntl_fork();
if($pid){
$proccesses[] = $pid;
}
else if($pid == -1){
die('FORK FAILED, STATUS -1');
}
else{
if(isset($myTask['recipient_model'])){
$this->currentModel = …Run Code Online (Sandbox Code Playgroud) 我有一个控制器测试,取决于Angular $ routeParams服务:
var $routeParams, MainCtrl, scope;
beforeEach(inject(function ($controller, $rootScope, $injector, $templateCache) {
scope = $rootScope.$new();
$routeParams = $injector.get('$routeParamsMock');
MainCtrl = $controller('MainCtrl', {
$scope: scope,
$routeParams: $routeParams,
});
}));
it('should load a pg from $routeParams', function(){
scope.userData = {};
$routeParams._setPg('PG_FIRST');
scope.$digest();
timeout.flush();
expect(scope.userData.pg).toBe(0);
$routeParams._setPg('PG_SECOND');
scope.$digest();
timeout.flush();
expect(scope.userData.pg).toBe(1);
});
Run Code Online (Sandbox Code Playgroud)
$ routeParamsMock:
!(function(window, angular){
'use strict';
angular.module('vitaApp')
.service('$routeParamsMock', function() {
var _pg = null;
return{
pg: _pg,
_setPg: function(pg){
_pg = pg;
}
}
});
})(window, window.angular);
Run Code Online (Sandbox Code Playgroud)
在调试测试时,我很惊讶地发现$ routeParamsMock.pg每次都返回null,即使我用不同的值调用_setPg.
是因为null被认为是一个原语(具有一种对象......),因此通过值传递?,或者可能是因为Angular正在复制传递给$ controller服务的对象?
我正在寻找的解决方案最好是不需要为每个不同的测试场景设置不同控制器的解决方案.例如: …
过去几周我从头开始构建我的应用程序.我在这里执行说明时这样做了.
我必须说一切都适用于任何普通的浏览器,如Mozilla或Chrome,而Angular.js框架对我来说非常有用.
问题是,使用IE8,一切似乎都被打破了,当我尝试为我的custome指令创建一个元素时,document.createElement DOM对象抛出一个错误(我也使用'x-'前缀,因为btowser这个蹩脚的借口所要求的).
屏幕截图:

应用指数:
<!DOCTYPE html>
<html xmlns:ng="http://angularjs.org" xmlns:x-restrict="" xmlns:x-fileupload="" class="ng-app" ng-app="myApp" ng-controller="homeCtrl">
<link rel="stylesheet" type="text/css" href="css/foundation.css">
<link rel="stylesheet" type="text/css" href="css/form.css">
<link rel="stylesheet" type="text/css" href="css/meta.css">
<!--[if lte IE 8]>
<script src="js/json3.min.js"></script>
<script>
document.createElement('ng-include');
document.createElement('ng-pluralize');
document.createElement('ng-view');
document.createElement('x-restrict');
document.createElement('x-fileupload');
// Optionally these for CSS
document.createElement('ng:include');
document.createElement('ng:pluralize');
document.createElement('ng:view');
</script>
<![endif]-->
<title>{{model.title}}</title>
</head>
<body>
<div class="errorBar" ng-show="model.error.visible"><div class="errorBarContent">{{model.error.message}}</div></div>
<div ng-include src="layout.menuSrc"></div>
<div class="colmask threecol">
<div class="colmid">
<div class="colleft">
<div class="col1">
<ng-view></ng-view>
</div>
<div class="col2">
<div ng-include src="layout.leftSideBarSrc"></div>
</div> …Run Code Online (Sandbox Code Playgroud) javascript internet-explorer-8 angularjs angularjs-directive
我想要实现的目标:将cordova本机处理程序包含在angular指令中
我想使用指令包装器为Cordova的本机事件实现处理程序(以便监听body load事件).
我有以下指令样板:
angular.module('vitaApp')
.directive('cordovaNative', function () {
return {
restrict: 'A',
compile: function (element, attrs, transcludeFn) {
alert('compile fired');
element.bind('load', function(){
alert('load occured');
});
},
link: function postLink(scope, element, attrs) {
alert('link fired');
element.bind('load', function(){
alert('load occured');
});
}
};
});
Run Code Online (Sandbox Code Playgroud)
以下列方式实例化:
<body ng-app="vitaApp" ng-controller="metaCtrl" ng-swipe-right="showMenu()" ng-swipe-left="hideMenu()" cordova-native>
Run Code Online (Sandbox Code Playgroud)
编译cordovaNative指令的函数会触发,但链接函数却没有.
它可能与ng-swipe指令有关(例如'{terminal:true}')?
注:我不尝试使用compile并link在一起,我想证明,非他们的作品申请使用的目的,load单独的事件.
视图.py
from rest_framework import viewsets
from rest_framework.response import Response
from rest_framework import generics
from ticker.serializers import PriceSerializer
from ticker.models import Price
import datetime
from nexchange.settings import DEFAULT_HOUR_RANGE
class LastPricesViewSet(viewsets.ViewSet):
def list(self, request):
queryset = Price.objects.filter().order_by('-id')[:2]
serializer = PriceSerializer(queryset, many=True)
return Response(serializer.data)
class PriceHistoryViewSet(generics.ListAPIView):
serializer_class = PriceSerializer
def get_queryset(self, request):
hours = self.request.query_params.get('hours', DEFAULT_HOUR_RANGE)
relevant = datetime.datetime.now() - datetime.timedelta(seconds=hours * 3600)
queryset = Price.objects.filter(created_on__gte=relevant).order_by('id')
return queryset
Run Code Online (Sandbox Code Playgroud)
网址.py:
from rest_framework.routers import SimpleRouter
from ticker.views import LastPricesViewSet, PriceHistoryViewSet
router = SimpleRouter()
router.register(r'price/latest', LastPricesViewSet, …Run Code Online (Sandbox Code Playgroud) angularjs ×6
javascript ×4
jasmine ×2
karma-runner ×2
php ×2
unit-testing ×2
cordova ×1
fork ×1
linkedin ×1
oauth ×1
pcntl ×1
phantomjs ×1
python ×1
seo ×1