我有一个ng-repeat打印列表项.我想编写一个自定义过滤器,以便只有条件为真时才会打印列表项.
我似乎有错误的结构,因为似乎变量没有传递给过滤器.
的index.php
<div ng-show="userDetails.username" class="nav">
<p>Menu</p>
<li ng-repeat="menuItem in menu | matchAccessLevel:$rootScope.userDetails.accessLevel:menuItem.minAccess | orderBy:'position' ">
<a ng-href="/angular-app/app/{{menuItem.id}}">{{menuItem.name}}</a>
</li>
</div>
Run Code Online (Sandbox Code Playgroud)
app.js
userApp.filter('matchAccessLevel', function() {
return function( item, userAccessLevel, minAccessLevel ) {
if( userAccessLevel >= minAccessLevel ) {
return item;
}
}
});
Run Code Online (Sandbox Code Playgroud) 我想if在Liquid中使用带有多个条件的语句.就像是:
{% if (include.featured == "true" and product.featured == "true") or (include.featured == "false" and product.featured == "false") %}
Run Code Online (Sandbox Code Playgroud)
多个条件似乎不起作用.我的语法错误了还是Liquid不能处理这种if语句?
我正在尝试在我的Mac上安装Bundler gem.使用命令:
sudo gem install bundler我收到以下错误:
ERROR: Could not find a valid gem 'bundler' (>= 0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed (https://s3.amazonaws.com/production.s3.rubygems.org/latest_specs.4.8.gz)
Run Code Online (Sandbox Code Playgroud)
它显然似乎是一个服务器问题,但我该如何解决这个问题呢?gem update --system目前是最新的.有没有另一种方法来获得Bundler?
我试图找出如何从插件外部调用我的jQuery插件中的函数.我试过的代码不起作用.我确定我必须重新构建我的插件以允许这个,但我不知道如何.在这个例子中,我正在尝试访问该underline()功能.
jQuery插件
(function($) {
"use strict";
$.fn.testPlugin = function(options) {
// Settings
var settings = $.extend({
newText : "Yabadabado"
}, options);
return this.each(function(i, el) {
var init = function(callback) {
if( $(el).attr("class") === "red" ) {
$(el).css("color","red");
}
$(el).text(settings.newText);
if( callback && typeof(callback) === "function" ) {
callback();
}
};
var underline = function() {
$(el).addClass("underline");
};
init();
});
};
}(jQuery));
Run Code Online (Sandbox Code Playgroud)
将插件分配给选择器
var doTest = $("#testItem").testPlugin({
newText: "Scoobydoo"
});
var doNewTest = $("#newTestItem").testPlugin({
newText: "kapow!"
});
Run Code Online (Sandbox Code Playgroud)
调用插件中的函数 …
我在Google地图中有一个动态生成的标记列表.我希望地图的中心成为所有标记的中心,并缩小到足以使所有标记都在视野中.
在计算地图中心方面,也许这可以通过遍历所有纬度和经度并找到中心点来实现.但是,我无法找出计算缩放应该是什么的最佳方法.
这有可能实现吗?
我的地图正在模板中使用,如下所示:
<ui-gmap-google-map events="map.events" center="map.center" zoom="map.zoom" draggable="true" options="options">
<ui-gmap-marker ng-repeat="home in filteredHomes = (resCtrl.filteredHomes | orderBy : $storage.params.orderby : $storage.params.reverseOrder)" coords="{latitude: home.location.latitude, longitude: home.location.longitude}" idkey="home.homeId">
</ui-gmap-marker>
</ui-gmap-google-map>
Run Code Online (Sandbox Code Playgroud)
UPDATE
从@Tiborg的建议尝试Angular实现:
uiGmapGoogleMapApi.then(function(maps) {
$scope.map = {
center: $scope.$storage.params.views.map.location,
zoom: $scope.$storage.params.views.map.zoom,
events: {
click: function() {
var bounds = new google.maps.LatLngBounds();
for (var i in $scope.filteredHomes) {
bounds.extend($scope.filteredHomes[i].location);
}
$scope.map.fitBounds(bounds);
}
}
};
});
Run Code Online (Sandbox Code Playgroud)
这会产生控制台错误: TypeError: undefined is not a function (evaluating 'a.lat()')
我$routeProvider的配置如下:
teachApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/teach/', {templateUrl: 'views/login_view.html'}).
when('/teach/overview', {templateUrl: 'views/overview_view.html'}).
when('/teach/users', {templateUrl: 'views/users_view.html'}).
otherwise({redirectTo: '/teach/'});
$locationProvider.html5Mode(true);
}]);
Run Code Online (Sandbox Code Playgroud)
在应用程序中,如果我点击链接,例如<a href="/teach/overview">Overview</a>,概述部分显示为预期.但是,当我手动将地址栏中的URL更改为完全相同的URL时,我收到404错误.被$routeProvider配置不正确?
我正在使用MAMP localhost和应用程序的根URL http://localhost/teach/
当元素处于活动状态时,我正在使用一个简单的指令来聚焦文本输入*ngIf.这包含在一个*ngFor循环中.
当第一个*ngIf激活时,输入按预期聚焦.当另一个输入被激活时,我收到错误:
EXCEPTION: Attempt to use a dehydrated detector.
我不明白这意味着什么以及如何防止错误.即使出现错误,该功能仍然有效.
@Directive({
selector: '[myAutoFocus]'
})
export class AutoFocusDirective {
constructor(private elem: ElementRef) {
window.setTimeout(function() {
elem.nativeElement.querySelector('input').focus();
});
}
}
Run Code Online (Sandbox Code Playgroud)
```
在我的Angular应用程序中,UI路由器解析了对控制器的承诺.当试图测试这个控制器时,Karma抱怨一个未知的提供者.如何将假对象注入测试以表示此解析对象.
我的应用程序代码如下所示:
angular.module('myapp')
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tab.name', {
...
resolve: {
allTemplates: function(Templates) {
return Templates.all().then(function(templates) {
return templates;
});
}
}
})
})
.controller('QueriesCtrl', function(allTemplates, UserQuery) {
var vm = this;
vm.queries = allTemplates;
vm.goToUrl = function(index, data) {
var processedUrl = UserQuery.process(data, vm.queryTyped[index]);
UserQuery.goToUrl(processedUrl);
};
});
Run Code Online (Sandbox Code Playgroud)
尝试运行测试时,我收到错误
Unknown provider: allTemplatesProvider <- allTemplates <- QueriesCtrl
Run Code Online (Sandbox Code Playgroud)
我已经尝试创建一个间谍并注入它,但这不起作用.这是我目前的测试:
describe('Unit: queriesCtrl', function() {
var controller,
scope,
UserQuery;
beforeEach(function() {
module('myapp');
inject(function($injector) {
UserQuery = $injector.get('UserQuery');
allTemplates = jasmine.createSpyObj('allTemplates', [{a:1}, {a:2}, {b:3}]); …Run Code Online (Sandbox Code Playgroud) 我已经按照PHP PhantomJS的安装指南进行了操作.使用PHP PhantomJS运行测试脚本时,我收到错误:
PHP Fatal error: Class 'JonnyW\PhantomJs\Client' not found in ...
我之前没有使用过Composer,所以我可能会忽略一些东西.我是从MAMP运行的,所以可能有一些细节与文档中没有提到的具体相关.如果我在浏览器中打开测试脚本,我会得到一个空白屏幕.它只是从终端运行php得到的Fatal error.
脚本失败的行是:
$client = Client::getInstance();
Run Code Online (Sandbox Code Playgroud)
因此,我认为它没有从Composer正确加载.我可以验证/bin两者都是phantomjs和phantomloader.
我应该采取哪些步骤才能正确加载PHP PhantomJS脚本?
--update--
test.php(直接取自PHP PhantomJS示例)
use JonnyW\PhantomJs\Client;
$client = Client::getInstance();
$request = $client->getMessageFactory()->createRequest();
$response = $client->getMessageFactory()->createResponse();
$request->setMethod('GET');
$request->setUrl('http://google.com');
$client->send($request, $response);
if($response->getStatus() === 200) {
echo $response->getContent();
}
Run Code Online (Sandbox Code Playgroud) 我是Angular的新手.我正在开发一个简单的登录表单,其中键入的用户名与从JSON查询返回的用户名进行比较.如果找到匹配项,则处理登录.
我觉得我这样做的方式并不安全,我是否认为可以通过浏览器的控制台访问返回的JSON字符串?
一旦我理解了如何正确地解决这个问题,我将在不久的将来为此添加密码检查.
我想指出正确的方向来解决用户登录Angular方式的问题.
app.js
angular.module('userApp', ["ngResource"]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/login', {templateUrl: 'partials/login.html', controller: LoginCtrl}).
when('/loggedin', {templateUrl: 'partials/user-admin.html', controller: UserCtrl}).
otherwise({redirectTo: '/login'});
}],[ '$locationProvider', function($locationProvider) {
$locationProvider.html5Mode = true;
}]).
factory("User", function($resource) {
return $resource("users/:userId.json", {}, {
query: {method: "GET", params: {userId: "users"}, isArray: true}
});
});
Run Code Online (Sandbox Code Playgroud)
controllers.js
function LoginCtrl($scope, $route, $routeParams, $location, User) {
$scope.users = User.query();
$scope.loginUser = function() {
var loggedin = false;
var totalUsers = $scope.users.length;
var usernameTyped = $scope.userUsername;
for( i=0; i < totalUsers; …Run Code Online (Sandbox Code Playgroud) angularjs ×5
javascript ×3
angular ×1
angular-ui ×1
apache ×1
bundler ×1
composer-php ×1
gem ×1
google-maps ×1
if-statement ×1
jasmine ×1
jekyll ×1
jquery ×1
karma-runner ×1
liquid ×1
mamp ×1
ng-repeat ×1
php ×1
ruby ×1
terminal ×1