根据AngularJS doc,调用$http
返回以下内容:
使用标准then方法和两个http特定方法返回promise对象:success和error.所述然后方法有两个参数一成功以及错误回调将与响应对象被调用.的成功和错误的方法采取一个参数-一当请求成功或失败分别将被调用的函数.传递给这些函数的参数是传递给then方法的响应对象的析构表示.
除了response
在一种情况下对象被解构的事实之外,我没有区别
promise.then
promise.success
/ promise.error
方法的参数传递有没有?这两种不同方式通过看似相同的回调有什么意义?
在:
module.directive 'name', ->
(scope, element, attr) ->
# Whatever implemenation
Run Code Online (Sandbox Code Playgroud)
执行scope
,element
并attrs
链接函数的参数依靠名称推断的依赖注入?如果是的话,我怎样才能使它们成为缩小证明?
或者他们依靠好的旧论据来命令传递给他们的是什么?
有没有办法将Meteor模板渲染为电子邮件的HTML正文?
例如,如果我想在该电子邮件中显示收集数据或生成动态链接.
在我的angularjs应用程序中,我以这种方式为http错误定义了一个默认处理程序:
myapp.config([ '$httpProvider', function($httpProvider) {
$httpProvider.responseInterceptors.push('errorInterceptor')
}])
Run Code Online (Sandbox Code Playgroud)
哪个errorInterceptor
服务在当前页面顶部的警报字段中显示有关错误的一些详细信息.
现在,当我想以不同的方式处理特定错误时(比如在模态中触发查询,我想仅在此模式中显示警报,而不是在页面级别):
$http.get('/my/request').then(success, specificErrorHandling)
Run Code Online (Sandbox Code Playgroud)
Angular确实specificErrorHandling
会触发我的errorInterceptor
,所以我的错误会被报告两次.有没有办法避免这种情况?
更一般地说,是否有一种Angular方法只处理promise
链中尚未处理的错误,就像服务器应用程序的顶级错误处理程序不必处理捕获的异常一样?
编辑:根据Beetroot-Beetroot在评论中的要求,这是我的拦截器的代码:
@app.factory 'errorInterceptor', [ '$q', 'alertsHandler',
($q, alertsHandler) ->
success = (response) ->
response
failure = (response) ->
alertsHandler.raise(response)
(promise) ->
promise.then success, failure
]
Run Code Online (Sandbox Code Playgroud) 我可以在Rails中做这样的事吗?
module Authored
belongs_to :user
attr_accessible creation_date
end
class Line < ActiveRecord::Base
include Authored
end
class Document < ActiveRecord::Base
include Authored
end
class User < ActiveRecord::Base
has_many :creations, :class_name => 'Authored'
end
Run Code Online (Sandbox Code Playgroud)
或者我是否需要使用简单继承,即使我的Authored类具有不同的类层次结构?
activerecord ruby-on-rails multiple-inheritance mixins ruby-on-rails-3
是否可以在MySQL选项文件my.ini/my.cnf中读取env vars,在httpd.conf和php.ini中使用$ {ENVVAR}语法的方式是可行的:
datadir="${MYSQL_DATA_HOME}/Data/"
Run Code Online (Sandbox Code Playgroud)
如果是,语法是什么?
我想做那样的somtehing:
angular.module('app', []).config(
[ '$httpProvider', 'customAuthService',
($httpProvider, customAuthService) ->
$httpProvider.defaults.transformRequest.push (data) ->
if customAuthService.isLoggedIn
data['api_key'] = {token: @token}
])
Run Code Online (Sandbox Code Playgroud)
根据Angularjs doc,我不能在config
我的块中执行它module
,因为那里不允许自定义服务,也不能在run
块中执行,因为$httpProvider
不允许那样的提供者:
配置块 - 在提供程序注册和配置阶段执行.只有提供程序和常量才能注入配置块.这是为了防止在完全配置服务之前意外实例化服务.
运行块 - 在创建注入器后执行并用于启动应用程序.只有实例和常量才能注入运行块.这是为了防止在应用程序运行时进一步进行系统配置.
如何在$httpProvider
依赖自制服务的情况下添加一些配置呢?
如果GET变量为空,有没有办法使用Typoscript条件为TypoScript TEXT分配不同的值?
像这样的东西:
xxxx.1 = TEXT
[globalVar = GP:print != ""]
xxxx.1.value = Absent
[else]
xxxx.1.value = Present
[end]
Run Code Online (Sandbox Code Playgroud)
当然这里!= ""
不起作用,所以我应该用什么呢?
whereami
Pry中的命令有简写吗?
如果没有,有没有办法在配置中为Pry命令定义别名.pryrc
?
angularjs ×4
javascript ×3
promise ×2
activerecord ×1
alias ×1
meteor ×1
minify ×1
mixins ×1
mysql ×1
pry ×1
ruby ×1
typo3 ×1
typoscript ×1