在单击复选框时,是否有一种更清晰的方式将焦点委托给元素.这是我入侵的脏版本:
HTML
<div ng-controller="MyCtrl">
<input type="checkbox" ng-change="toggled()">
<input id="name">
</div>
Run Code Online (Sandbox Code Playgroud)
JavaScript的
var myApp = angular.module('myApp',[]);
function MyCtrl($scope, $timeout) {
$scope.value = "Something";
$scope.toggled = function() {
console.debug('toggled');
$timeout(function() {
$('#name').focus();
}, 100);
}
}
Run Code Online (Sandbox Code Playgroud)
JSFiddle:http://jsfiddle.net/U4jvE/8/
提前感谢大家 -
alert((~1).toString(2));
Run Code Online (Sandbox Code Playgroud)
输出: -10
但是在PHP/Java中它输出11111111111111111111111111111110
我错过了什么,为什么Javascript会在输出中添加" - "?
谢谢,山姆
我有一个开发和生产环境,我的URL有所不同:
生产:
www.exmaple.com/page
发展:
dev.environment/project/page
我知道我可以在AngularJS中设置基本URL
<base href='/project/' />
但这对我没有帮助.在我加载AngularJS应用程序之前,我获取一个配置文件(在app.js中,带有.run语句,该语句读取具有环境的变量:
]).run([
'$rootScope',
'$http',
function (
$rootScope,
$http
) {
var configDeferred = $q.defer();
// fetch config and set the API
$http.get('config.json').then(function(response) {
$rootScope.config = response.data;
configDeferred.resolve();
});
// Wait for the config to be loaded, then go to state
$rootScope.$on('$stateChangeStart', function (event, next, current) {
event.preventDefault();
$q.all([configDeferred.promise]).then(function() {
$state.transitionTo(next.name);
return;
});
});
Run Code Online (Sandbox Code Playgroud)
有没有办法根据AngularJS中提取的配置文件(可能带有.htaccess)动态设置基本URL?
尝试1:
尝试.run通过ng-href 获取配置并设置基本URL:
在我的app.js中编辑以下代码行:
// fetch config and set the API
$http.get('config.json').then(function(response) { …Run Code Online (Sandbox Code Playgroud) 我有一个具有指定值的控制器:
$scope.post = 'please visit http://stackoverflow.com quickly';
Run Code Online (Sandbox Code Playgroud)
我的html中有一些文字:
<p>{{post}}</p>
Run Code Online (Sandbox Code Playgroud)
我想创建一个url的可点击链接(用锚标签包围它).
我试图将我的HTML更改为:
<p ng-bind-html="post | createAnchors"></p>
Run Code Online (Sandbox Code Playgroud)
以下是该问题的简化示例:
问题是,我怎样才能逃脱整个帖子文本,除了链接,它将被锚标签包围??
我有一个requireJS设置,包含预编译的Handlebars模板和我在数据库中的翻译i18next.我需要按以下顺序做一些事情:
我的requireJS配置文件如下所示:
require.config({
deps: ["main"],
paths: {
'handlebars.runtime': "../assets/js/libs/handlebars.runtime.amd.min",
i18n: "../assets/js/libs/i18next-1.7.1",
// Shim Plugin
use: "../assets/js/plugins/use"
},
use: {
i18n: {
attach: "i18n"
}
}
});
Run Code Online (Sandbox Code Playgroud)
我的main.js文件看起来像这样,需要namespace.js:
require([
'namespace',
'modules/Transport'
], function (
namespace,
$,
Transport
) {
var Router = Backbone.Router.extend({
routes: {
'*any': 'any'
},
Run Code Online (Sandbox Code Playgroud)
我namespace.js将尝试注册Handlebars助手并使用翻译初始化i18next:
define([
"handlebars.runtime",
"use!i18n"
], function(
Handlebars,
i18n
) {
var defaultLanguage = 'en';
var translations;
$.when(
$.getJSON('/api/translations', function …Run Code Online (Sandbox Code Playgroud) 我正在使用angular-ui-router来控制我的AngularJS应用程序中的状态.在一个部分我使用jquery-file-upload.我遇到的问题是,当我使用jquery-file-upload给出的示例时,是它在模板中定义控制器,如下所示:
<!-- The file upload form used as target for the file upload widget -->
<form id="fileupload" action="//jquery-file-upload.appspot.com/" method="POST"
enctype="multipart/form-data" data-ng-app="demo"
data-ng-controller="DemoFileUploadController" data-file-upload="options"
data-ng-class="{'fileupload-processing': processing() || loadingFiles}">
...
</form>
Run Code Online (Sandbox Code Playgroud)
表单标签有data-ng-controller="DemoFileUploadController".在我的控制器中,这将创建所需的所有文件上载方法(如$scope.submit()和$scope.queue)
问题是我定义了我的控制器angular-ui-router风格,如下所示app.js:
$stateProvider.state('upload', {
url: "/upload",
views: {
"upload": {
templateUrl: "app/partials/upload.html",
controller: 'DemoFileUploadController'
},
}
})
Run Code Online (Sandbox Code Playgroud)
但是这段代码会导致我的文件上传方法,而不是在我的控制器中加载(或绑定)(没有$scope.submit()和$scope.queue).
有没有办法一起使用angular-ui-router和jquery-file-upload?
file-upload angularjs angular-ui jquery-file-upload angular-ui-router
关于PSR-0的实现以及必须从命令行执行哪些命令,我需要采取哪些步骤从Kohana 3.2升级到3.3?
在AngularJS中,没有一致的方法来测试不同的表单属性.我知道AngularJS用Protractor更新了他们的e2e测试,但对于仍然使用旧版本的每个人,我想知道以下两者之间的区别:
选择项目:
1A.从选择(下拉列表)列表中选择项目
1B.选择单选按钮
1C.选中复选框
检查是否选中:
2A.检查是否选择了下拉列表
2B.检查是否选择了单选按钮
2C.检查是否选中了复选框
我有一个触发HTTP请求的服务.此请求使用$ rootScope.config对象(存储了我的基本URL),但出于某种原因,当我使用$ httpBackend时,$ rootScope未正确加载.
服务:
myAppServices.factory('Auth', function($rootScope, $http, $cookieStore){
return {
logout: function(success, error) {
$http.get($rootScope.config.apiUrl + '/users/logout').then(function(response){
}, function(response) {
});
}
Run Code Online (Sandbox Code Playgroud)
测试:
describe('services', function() {
var Auth;
var $httpBackend;
var $cookieStore;
var $rootScope;
beforeEach(function() {
module('myApp.services');
});
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
$cookieStore = $injector.get('$cookieStore');
$rootScope = $injector.get('$rootScope');
Helper = $injector.get('Helper');
Auth = $injector.get('Auth');
}));
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
describe('logout', function() {
it('should make a request and invoke callback', function() {
// I try to set $rootScope …Run Code Online (Sandbox Code Playgroud) angularjs ×6
javascript ×2
.htaccess ×1
amd ×1
anchor ×1
angular-ui ×1
base-url ×1
checkbox ×1
config ×1
environment ×1
file-upload ×1
http ×1
httpbackend ×1
hyperlink ×1
i18next ×1
kohana ×1
kohana-3.2 ×1
kohana-3.3 ×1
radio-button ×1
requirejs ×1
sanitize ×1
unit-testing ×1
unix ×1