我有一个实现向导的简单多视图Angular应用程序,因此每次用户单击"下一步"按钮时,应用程序将导航到下一个视图,"后退"按钮也相同.我有一个$routeProvider配置将所有视图绑定到同一个控制器.每个视图代表一个包含输入字段的巨大表单块,并$routeProvider管理它们之间的导航:
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider.when('/salespoints', {
templateUrl: 'salespoints',
controller: 'main'
})
.when('/users', {
templateUrl: 'users',
controller: 'main'
})
.otherwise({
templateUrl: 'partner',
controller: 'main'
});
$locationProvider.hashPrefix('');
}]);
Run Code Online (Sandbox Code Playgroud)
问题是,每次用户单击"下一步"或"返回"时,都会调用控制器,因此$scope以前步骤所做的所有更改都会丢失:
app.controller('main', ['$scope', function ($scope) {
console.log('controller invoked'); // appears each time a user presses "Next" or "Back", hence re-instantiation of $scope
}]);
Run Code Online (Sandbox Code Playgroud)
应用程序足够小$rootScope,以防万一其他方法失败,但我只想避免这种情况作为反模式.
保持$scope最新状态的最佳方法是什么,从应用程序实例的生命周期的一开始就进行所有更改,而不是在每次更改视图时重新实例化?
javascript angularjs angularjs-scope angularjs-routing angularjs-view
我使用emacs(更确切地说是Spacemacs),到目前为止,除了打开./project.clj并添加一个项目,我还没有其他方法可以向项目中添加项目依赖项(例如,ring或打ic)。的新向量:dependencies。我这样做并不自在,因为我需要记住要添加为依赖的程序包的确切版本,并乘以这些程序包的可能数量,这样的信息量显然不是人为的。同时,我强烈感觉可以通过CLI或直接在emacs中添加项目依赖关系(也许是Cider?)。有可能吗,我该怎么做?
根据在IE6中将indexOf方法添加到Array类的方法,我现在如何通过迭代任意随机数组来拒绝此方法?例如:
Array.prototype.indexOf = function(needle) { ... };
var array = [1, 2, 3];
for (var i in array) {
document.write(i + ': ' + array[i]);
}
Run Code Online (Sandbox Code Playgroud)
给出输出
0: 1
1: 2
2: 3
indexOf: function ...
Run Code Online (Sandbox Code Playgroud)
如何跳过indexOf属性并停止迭代它而不向其中添加任何代码
for(...)
Run Code Online (Sandbox Code Playgroud)
叫做?
一个非常简单的代码
var App = React.createClass({
handleForm: (e) => {
e.preventDefault();
},
render: () => {
return (
<form>
<button type="submit" onClick={this.handleForm}>Go</button>
</form>
);
}
});
Run Code Online (Sandbox Code Playgroud)
获取转换为
// ...
_react2['default'].createElement(
'button',
{ type: 'submit', onClick: undefined.handleFormSubmit },
'Go'
)
Run Code Online (Sandbox Code Playgroud)
但为什么?我是否需要明确地绑定所有内容(包括this.setState我出于同样的原因无法工作)?
我正在使用反应0.13.3与webpack 1.12.2和babel-loader 5.3.2.以前没有遇到过这样的问题.
我正在制作一个小的 Meteor 包。它使用了另外两个在其package.js. 出于测试目的,我从本地系统添加了这个包(它没有发布在 Atmosphere 上)。运行应用程序后,我不断收到错误消息:
=> Started proxy.
=> Started MongoDB.
=> Errors prevented startup:
While selecting package versions:
error: unknown package in top-level dependencies: whoever:whatever
Run Code Online (Sandbox Code Playgroud)
我什至在应用程序中明确添加了所需的包,但它没有帮助。
的package.js:
Package.describe({
name: 'whoever:whatever',
version: '0.0.1',
summary: 'Whatever the summary is',
git: 'https://github.com/whoever/whatever',
documentation: 'README.md'
});
Package.onUse(function(api) {
api.versionsFrom('1.1.0.3');
api.use('http');
api.use('jparker:crypto-sha1', 'server');
api.use('simple:reactive-method', 'client');
api.addFiles('for-a-server.js', 'server');
api.addFiles([
'for-a-client.js',
'for-a-client.html'
], 'client');
});
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?接下来我应该寻找什么?