在模块中,控制器可以从外部控制器继承属性:
var app = angular.module('angularjs-starter', []);
var ParentCtrl = function ($scope, $location) {
};
app.controller('ChildCtrl', function($scope, $injector) {
$injector.invoke(ParentCtrl, this, {$scope: $scope});
});
Run Code Online (Sandbox Code Playgroud)
示例:死链接:http://blog.omkarpatil.com/2013/02/controller-inheritance-in-angularjs.html
模块内的控制器也可以继承兄弟姐妹吗?
var app = angular.module('angularjs-starter', []);
app.controller('ParentCtrl ', function($scope) {
//I'm the sibling, but want to act as parent
});
app.controller('ChildCtrl', function($scope, $injector) {
$injector.invoke(ParentCtrl, this, {$scope: $scope}); //This does not work
});
Run Code Online (Sandbox Code Playgroud)
第二个代码不起作用,因为$injector.invoke
需要一个函数作为第一个参数,并且找不到引用ParentCtrl
.
当使用AngularJS"http get then"构造(promises)时,如何处理HTTP错误,例如500?
$http.get(url).then(
function(response) {
console.log('get',response)
}
)
Run Code Online (Sandbox Code Playgroud)
问题是,对于任何非200 HTTP响应,都不会调用内部函数.
如何在AngularJS表单元素内的输入字段中自动调整第一个字符的资本?
我已经看到了jQuery解决方案,但是相信在AngularJS中必须通过使用指令来完成.
我刚刚完成了Hello World Google Cloud Functions教程并收到了以下响应标头:
Connection ? keep-alive
Content-Length ? 14
Content-Type ? text/plain; charset=utf-8
Date ? Mon, 29 Feb 2016 07:02:37 GMT
Execution-Id ? XbT-WC9lXKL-0
Server ? nginx
Run Code Online (Sandbox Code Playgroud)
如何添加CORS标头以便能够从我的网站调用我的功能?
我正在使用ng-boilerplate,并且必须根据用户配置添加在生产中使用不同模板的可能性.
.config(function config( $stateProvider ) {
$stateProvider.state( 'demo', {
url: '/demo',
views: {
"main": {
controller: 'DemoCtrl',
templateUrl: 'demo/demo.tpl.html'
}
}
});
})
Run Code Online (Sandbox Code Playgroud)
我目前的想法是使templateUrl动态化
templateUrl: 'demo/demo'+userService.getTemplate()+'.tpl.html'
Run Code Online (Sandbox Code Playgroud)
并有多个模板文件,如:
而userService函数确实提供了要使用的模板版本,例如".b"
你同意吗?是否有更好/更容易解决此问题的方法?
我有一个选择标记(用于国家选择),我想使用指令预先填充选项:
<select class="countryselect" required ng-model="cust.country"></select>
Run Code Online (Sandbox Code Playgroud)
我的指示如下
return {
restrict : "C",
link: function postLink(scope, iElement, iAttrs) {
var countries = [
["AND","AD - Andorra","AD"],
["UAE","AE - Vereinigte Arabische Emirate","AE"]
... //loop array and generate opt elements
iElement.context.appendChild(opt);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以使用其他选项填充选择,但ng-model绑定不起作用.即使cust.country具有值(例如"UAE"),也不会选择该选项.
如何使select显示cust.country的值?如果认为我在这里有一些时间问题.
在我的离线webapp缓存期间,我收到一个完全有效的错误,该错误显示在浏览器控制台中,如下所示:
Application Cache Error event: Manifest changed during update, scheduling retry
Run Code Online (Sandbox Code Playgroud)
我可以添加一个监听器,以通知发生了错误.
window.applicationCache.addEventListener('error', function(e){
//handle error here
}, false);
Run Code Online (Sandbox Code Playgroud)
如何获取错误详细信息,在这种情况下" 更新期间更改了清单,调度重试 "?
我想通过utl_http将UTF8 json字符串通过POST发送到node.js服务器。发送字符串
["Sant Julià de Lòria"]
Run Code Online (Sandbox Code Playgroud)
确实到达
["Sant Juli� de L�ria"]
Run Code Online (Sandbox Code Playgroud)
PL / SQL代码如下所示:
FUNCTION http_post_varchar(
p_url VARCHAR2,
p_request_body VARCHAR2 )
RETURN VARCHAR2
AS
req UTL_HTTP.REQ;
resp UTL_HTTP.RESP;
value VARCHAR2(32767); -- URL to post to
v_url VARCHAR2(200) := p_url;
-- Post Parameters
v_param VARCHAR2(32767) := p_request_body;
v_param_length NUMBER := length(v_param);
BEGIN
req := UTL_HTTP.BEGIN_REQUEST (url=> v_url, method => 'POST');
UTL_HTTP.SET_HEADER (r => req,
name => 'Content-Type',
value => 'application/json;charset=UTF-8');
UTL_HTTP.SET_HEADER (r => req,
name => 'Content-Length',
value => v_param_length);
UTL_HTTP.WRITE_TEXT …
Run Code Online (Sandbox Code Playgroud) 我正在接收使用Google App Engine Python的电子邮件,并将其存储在数据存储区中.
class LogSenderHandler(InboundMailHandler):
def receive(self, mail_message):
logging.info("Received a message from: " + mail_message.sender)
Run Code Online (Sandbox Code Playgroud)
当我收到来自ASCII地址的电子邮件时,一切正常:
我[me@gmail.com]存储为Me [me@gmail.com]
但是,如果发送方值包含非ascii字符,则存储的数据值如下所示:
Kröber先生[mr.kroeber@gmail.com]存储为=?ISO-8859-1?Q?Mr_Kr = F6ber?= [mr.kroeber@gmail.com]
angularjs ×5
javascript ×2
ab-testing ×1
angular-http ×1
ascii ×1
capitalize ×1
cors ×1
email ×1
encoding ×1
html5 ×1
http ×1
inheritance ×1
input ×1
oracle ×1
plsql ×1
post ×1
promise ×1
python ×1
utf-8 ×1