我目前使用service/$ resource来进行ajax调用(在这种情况下为GET),并且IE缓存调用以便无法从服务器检索新数据.我使用了一种技术,我通过谷歌搜索创建一个随机数并将其附加到请求,以便IE不会去缓存数据.
有没有比将cacheKill添加到每个请求更好的方法?
工厂代码
.factory('UserDeviceService', function ($resource) {
return $resource('/users/:dest', {}, {
query: {method: 'GET', params: {dest: "getDevicesByUserID"}, isArray: true }
});
Run Code Online (Sandbox Code Playgroud)
来自控制器的呼叫
$scope.getUserDevices = function () {
UserDeviceService.query({cacheKill: new Date().getTime()},function (data) {
//logic
});
}
Run Code Online (Sandbox Code Playgroud) 我有一个模态窗口,用于向用户呈现表单.他们输入信息然后按下按钮点击按钮.服务器处理请求并发回响应.当响应成功时,我想从控制器关闭模态窗口.怎么能实现这一目标?
模态是部分包含在另一页中
主页:
<!-- main content -->
<p>Foo</p>
<!-- angular directive -->
<foo-directive></foo-directive>
Run Code Online (Sandbox Code Playgroud)
该指令的内容:
<div ng-controller="FooCtrl">
<ul class="thumbnails">
<li class="span3 tile tile-white" ng-repeat="foo in model.foo">
<div>
{{foo.bar}}
</div>
<div>
({{foo.bam}})
</div>
<div>
<a data-toggle="modal" href="#myModal"><img src="{{foo.imgPath}}"></a>
</div>
</li>
</ul>
<!-- foo modal partial included by ejs -->
<% include foo_modal.ejs %>
</div>
Run Code Online (Sandbox Code Playgroud)
模态标记:
<div id="fooModal" class="modal hide fade in" style="display: none; ">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>New Device</h3>
</div>
<div class="modal-body">
<h4>Foo Modal</h4>
<div ng-controller="FooCtrl">
<form name="fooFrm">
<input id="email" …
Run Code Online (Sandbox Code Playgroud) 作品:
var mongoose = require('mongoose');
var db = function() {
return {
config: function(conf) {
mongoose.connect('mongodb://' + conf.host + '/' + conf.database);
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback() {
console.log('db connection open');
});
}
};
};
module.exports = db();
Run Code Online (Sandbox Code Playgroud)
不起作用:
var mongoose = require('mongoose');
var db = function() {
return {
config: function(conf) {
var db = mongoose.createConnection('mongodb://' + conf.host + '/' + conf.database);
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback() {
console.log('db connection open'); …
Run Code Online (Sandbox Code Playgroud) 我需要从指令中的父控制器继承范围.我不一定要留下范围:false.我也不一定想要使用隔离范围,因为它需要大量的工作才能使我关心的值正确链接(在父控制器中考虑很多值).
scope:true
如果我想更新父范围,在我的指令中使用是否有意义?
<div ng-controller="MyCtrl">
Hello, {{name}}!
<my-directive></my-directive>
</div>
Run Code Online (Sandbox Code Playgroud)
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
function MyCtrl($scope) {
$scope.name = 'Dave';
}
myApp.directive('myDirective', function() {
return {
scope: true,
restrict: 'EA',
link: function(scope, elem, attrs) {
scope.updateName = function(newName) {
console.log('newName is: ' + newName);
scope.name = newName;
}
},
template: '<input ng-model="updatedName" placeholder="new name value"> <button ng-click="updateName(updatedName)">Update</button>'
}
})
Run Code Online (Sandbox Code Playgroud)
请查看小提琴
我想访问父指令的范围,但我似乎无法获得正确的设置组合.这是可能的,这是正确的方法吗?
我真的想避免在MyCtrl中放置类似SOME_CONST(这可以帮助我通过控制流程进行DOM更新)
<div ng-controller="MyCtrl">
<parent>
<child></child>
</parent>
</div>
var myApp = angular.module('myApp',[]);
function MyCtrl($scope) {
$scope.obj = {prop:'foo'};
}
myApp.directive('parent', function() {
return {
scope: true,
transclude: true,
restrict: 'EA',
template: '<div ng-transclude><h1>I\'m parent {{obj.prop}}<h1></div>',
link: function(scope, elem, attrs) {
scope.SOME_CONST = 'someConst';
}
}
});
myApp.directive('child', function() {
return {
restrict: 'EA',
template: '<h1>I\'m child.... I want to access my parent\'s stuff, but I can\'t. I can access MyCtrlScope though, see <b>{{obj.prop}}</b></h1> how can I access the <b>SOME_CONST</b> value …
Run Code Online (Sandbox Code Playgroud) 我有一个指令,我想要另一个指令,以便能够调用.我一直在尝试使用指令控制器来尝试实现这一点.
指令1将与指令2位于同一页面上,指令1将调用指令2的控制器公开的方法:
指令1:
'use strict';
angular.module('angularTestApp')
.directive('fileLibrary', function () {
return {
templateUrl: 'views/manage/file_library/file-library.html',
require: 'videoClipDetails',
restrict: 'AE',
link: function postLink(scope, element, attrs, videClipDetailsCtrl) {
scope.doSomethingInVideoClipDirective = function() {
videClipDetailsCtrl.doSomething();
}
}
};
});
Run Code Online (Sandbox Code Playgroud)
指令二:
'use strict';
angular.module('angularTestApp')
.directive('videoClipDetails', function () {
return {
templateUrl: 'views/video_clip/video-clip-details.html',
restrict: 'AE',
controller: function($scope, $element) {
this.doSomething = function() {
console.log('I did something');
}
},
link: function postLink(scope, element, attrs) {
console.log('videoClipDetails directive');
//start the element out as hidden
}
};
});
Run Code Online (Sandbox Code Playgroud)
使用两者并将其设置为兄弟姐妹的文件:
<div> …
Run Code Online (Sandbox Code Playgroud) 观看http://egghead.io上的视频,我看到作者使用console.log来注销$ scope或scope对象的内容.Chrome中的输出是可钻取的对象.但是,当我这样做时,Chrome提供的输出是:
[object Object]
No Properties
Run Code Online (Sandbox Code Playgroud)
使用console.dir具有相同的效果.有什么建议?
谢谢,
我的团队一直在使用Node.js,Twitter Boostrap,Mongo DB和Mule为ESB编写仪表板应用程序.
最近,一位高管要求我们改变我们对像Liferay这样的Portal/Portlet容器的方法.
我们团队中的一些人有Liferay的经验,我们对此有非常消极的感受.处理完整页面刷新,portlet生命周期,样式和主题问题以及有限的DBMS覆盖率等问题是我们的投诉列表中的首要问题.
我们看到我们的管理团队来自哪里.他们已经决定,他们希望使仪表板可扩展,轻松或更容易插入其他组.
有没有一个解决方案可以平衡用户的现代Web期望与IT专业人员和负责建立和扩展应用程序的管理人员的企业需求,如Liferay?可插拔小部件在这里很重要.
节点显然是我们的偏好,像Grails这样的东西紧随其后.
谢谢,
在SailsJS中登录的实际语法是什么?
文档没有任何内容,但在网站的路线图中找到了以下内容
"将Sails.log(winston包装纸)作为一个单独的模块拉出来,以便它可以被水线使用"
我想象它是这样的:
Sails.log(...)
Sails.error(...)
Sails.warn(...)
Run Code Online (Sandbox Code Playgroud) 我在一个项目中使用Q,而我正在使用bower来管理我的JS依赖项.我在bower.json中包含了Q 2.0.0和bower
"dependencies" : {
"q": "~2.0.0"
}
Run Code Online (Sandbox Code Playgroud)
在我的index.html中,我将Q包含在脚本标记中
<script src="bower_components/q/q.js"></script>
Run Code Online (Sandbox Code Playgroud)
当我加载页面时,我在控制台中看到:
未捕获的ReferenceError:require未定义q.js:43
q.js的第43行:
require("collections/shim");
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?我应该使用Browserify或require.js来实现这一点吗?我希望只需使用标签就可以访问该库.