我想要实现的是为输入字段添加额外的接口,以便通过单击+和 - 按钮来增加和减少其中的数值.
(本质上它是输入[type = number]字段在chrome上的内容,但我希望这是跨浏览兼容的,并且还可以完全控制所有浏览器的演示文稿).
代码在视图中:
<input data-ng-model="session.amountChosen" type="text" min="1" class="form-control input-small" data-number-input>
Run Code Online (Sandbox Code Playgroud)
指令代码:
app.directive('numberInput', function() {
return {
require: 'ngModel',
scope: true,
link: function(scope, elm, attrs, ctrl) {
var currValue = parseInt(scope.$eval(attrs.ngModel)),
minValue = attrs.min || 0,
maxValue = attrs.max || Infinity,
newValue;
//puts a wrap around the input and adds + and - buttons
elm.wrap('<div class="number-input-wrap"></div>').parent().append('<div class="number-input-controls"><a href="#" class="btn btn-xs btn-pluimen">+</a><a href="#" class="btn btn-xs btn-pluimen">-</a></div>');
//finds the buttons ands binds a click event to them where the …Run Code Online (Sandbox Code Playgroud) 我看到famo.us 示例主要是指Modifier类,但famo.us大学教程主要引用StateModifier类.
这两者有何不同,哪种是最合适的应用?
我正在尝试从包含多个曲面(甚至是内部视图)的视图中创建Scrollview,但它不会滚动.它只是填充内容直到折叠并且不向下滚动(不响应鼠标滚轮或触摸手势).
视图类中创建Scrollview的函数:
function _createScrollView () {
this.scrollView = new Scrollview();
var surfaces = [];
this.scrollView.sequenceFrom(surfaces);
for (var i = 0, temp; i < 40; i++) {
temp = new ContentRow({ orderNumber : i });
temp.pipe(this.scrollView);
surfaces.push(temp);
}
this.scrollViewMod = new StateModifier({
transform : Transform.translate(0, 80, 0)
});
this.add(this.scrollViewMod).add(this.scrollView);
}
Run Code Online (Sandbox Code Playgroud)
这是我希望进一步详细开发的完整ContentRow类,并且是更大的scrollview序列的一部分:
define(function(require, exports, module) {
var View = require('famous/core/View');
var Surface = require('famous/core/Surface');
var Transform = require('famous/core/Transform');
var StateModifier = require('famous/modifiers/StateModifier');
function ContentRow() {
View.apply(this, arguments);
this.add(new Surface({
content: "Surface: " …Run Code Online (Sandbox Code Playgroud) 我正在开发一个小型游戏/模拟应用程序,我需要一个应用程序范围的时间变量来更新自己.它也可以是一个数字变量,对于我所关心的所有内容都在不断增加,例如每秒0..1..2..3..4,以表示此模拟应用程序中的时间进度.(这不一定是JavaScript Date Object本身)
我希望它可以在我注入的每个控制器/服务中访问,并在整个应用程序中自动更新.然后,依赖于此时间变量的其他范围变量将自动更新AngularJS提供的所有双向绑定好东西.
这甚至是AngularJS app dev哲学中的"合法"线吗?如果是,那么构建它的最佳方法是什么?