我正在尝试做一些简单的事情 - 在一些实体保存后(使用http请求)我想导航回列表路由.问题是:如何订阅成功动作(或者可能是减速器或效果?)
这是我的行为代码:
static SAVE_POST = '[POST] Save POST';
savePOST(Post): Action {
return {
type: PostActions.SAVE_POST,
payload: Post
};
}
static SAVE_POST_SUCCESS = '[POST] Save POST Success';
savePOSTSuccess(Post): Action {
console.log('action: savePostSuccess')
return {
type: PostActions.SAVE_POST_SUCCESS,
payload:Post
};
}
Run Code Online (Sandbox Code Playgroud)
我正在使用效果:
@Effect() savePost$ = this.update$
.ofType(PostActions.SAVE_POST)
.map(action => action.payload)
.switchMap(post => this.svc.savePost(post))
.map(post => this.postActions.savePOSTSuccess(post));
Run Code Online (Sandbox Code Playgroud)
减速器:
const initialState: PostListState = [];
export default function (state = initialState, action: Action): PostListState {
switch (action.type) {
case PostActions.LOAD_POST_SUCCESS: {
return action.payload;
} …Run Code Online (Sandbox Code Playgroud) 我复制了一个knockoutjs的例子:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/knockout/2.2.0/knockout-min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
<h2>Participants</h2>
Here are the participants:
<div data-bind="template: { name: 'person-template', data: buyer }"></div>
<div data-bind="template: { name: 'person-template', data: seller }"></div>
<script id="person-template" type="text/html">
<h3 data-bind="text: name"></h3>
<p>Credits: <span data-bind="text: credits"></span></p>
</script>
<script type="text/javascript">
function MyViewModel() {
this.buyer = { name: 'Franklin', credits: 250 };
this.seller = { name: 'Mario', credits: 5800 };
}
ko.applyBindings(new MyViewModel());
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
当我将jQuery更新为1.9版时,我遇到以下错误:
Uncaught TypeError: Object …Run Code Online (Sandbox Code Playgroud) 我正在构建使用CORS请求的应用程序.我使用的每个请求都从常量中获取主机地址
angular.module('siteApp').constant('baseUrl', {
'server':'htttp://localhost/',
})
Run Code Online (Sandbox Code Playgroud)
在每个服务我用来发送这样的请求:
angular.module('siteApp').factory('DocsSvc', function ($http, baseUrl) {
var baseurl = baseUrl.server ;
$http.get(baseurl + 'document')
Run Code Online (Sandbox Code Playgroud)
是否有可能使'htttp:// localhost /'值 - 来自config.json文件到baseUrl constant或baseUrl factory?我的意思是:我如何从ajax请求中加载一些东西,让它可以访问app模块
我试过了:
.run(['$rootScope', , function ($rootScope) {
$.ajax('config.json', {async: false})
.success(function (data) {
$rootScope.HOST = data.HOST;
});
Run Code Online (Sandbox Code Playgroud)
并尝试从baseUrl访问它:
angular.module('siteApp').factory('baseUrl',function($rootScope) {
return {
server: $rootScope.HOST
Run Code Online (Sandbox Code Playgroud)
但没有运气 - baseUrl.server未定义为函数
我正在使用knockoutjs,我正在尝试从JSON数据填充ViewModel实例.根据knockoutjs文档,我可以使用此声明:
ko.mapping.fromJS(data, viewModel);
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
var pledgeVM=function(){
this.name=ko.observable();
this.Assets=ko.observableArray([]);
this.StartEdit=function(assetModel){
};
};
pledge = {"name":"Moses","Assets":[{"CityId":13,"commetns":null},{"CityId":14,"commetns":null}]};
var pledgeVMinstance=new pledgeVM();
ko.mapping.fromJS(pledge,pledgeVMinstance);
Run Code Online (Sandbox Code Playgroud)
由于某种原因,数据未填充(pledgeVMinstance.name()未定义),除非我将语句更改为:
ko.mapping.fromJS(pledge,{},pledgeVMinstance);
Run Code Online (Sandbox Code Playgroud)
可能有人可以解释我为什么会这样.
谢谢
我构建服务,应该在构建服务器API之前暂时返回某些数组的Observable.在将angular和其他软件包升级到6.0.0-rc.3版本之前,我使用了以下语法:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
@Injectable()
export class GeocodesService {
getPositions():Observable<any>{
return Observable.of({ })
}
}
Run Code Online (Sandbox Code Playgroud)
在6.0.0-rc.3,此语法看起来已弃用尝试按照以下方式导入它(使用最新的角度):
import 'rxjs/observable/of'
Run Code Online (Sandbox Code Playgroud)
但获得错误:
Module not found: Error: Can't resolve 'rxjs/observable/of'
Run Code Online (Sandbox Code Playgroud)
如何使用最新的rxjs进行"of"的导入?
谢谢
我正在尝试构建应该隐藏的动画垂直面板
当用户单击按钮时,面板应从右侧滑动。这是我的代码:
HTML:
<body ng-controller="Ctrll">
<p style="color:#000;margin:0"><span>slide:</span>{{slide}} </p>
<button ng-click="showAlerts()" style="float:left">
click to toggle panel
</button>
<!--sliding panel directive-->
<alerts-center></alerts-center>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="js/index.js"></script>
</body>
Run Code Online (Sandbox Code Playgroud)
CSS:
body{
background-color:#FFF;
height:100%;
width:100%;
margin:0;
color:#FFF;
font-size:3em;
line-height:100px;
text-align:center;
overflow:hidden;
}
.animate-slide {
background:#30373f;
position:absolute;
width: 320px;
height:100%;
top: 0;
right:0px;
}
.animate-slide.ng-hide-add,
.animate-slide.ng-hide-remove {
display:none;
-webkit-transition:0.5s linear all;
-moz-transition:0.5s linear all;
-o-transition:0.5s linear all;
transition:0.5s linear all;
}
.animate-slide.ng-hide-remove.ng-hide-remove-active {
-webkit-animation:0.5s slide-left;
animation:0.5s slide-left;
}
.animate-slide.ng-hide-add.ng-hide-add-active {
-webkit-animation:0.5s slide-right;
animation:0.5s slide-right; …Run Code Online (Sandbox Code Playgroud) 我正在努力教自己angular2.我试图构建组件"触发器调整大小",我想渲染为:
<a class="hidden-xs" href="">
<em class="fa fa-navicon"></em>
</a>
Run Code Online (Sandbox Code Playgroud)
而不是:
<trigger-resize>
<a class="hidden-xs" href="">
<em class="fa fa-navicon"></em>
</a>
</trigger-resize>
Run Code Online (Sandbox Code Playgroud)
(我不希望自定义选择器渲染)
在角度1.我知道它将通过"replace:true"选项实现,但是有可能在angular2中实现它吗?
亲切的问候
我是 Angular 5 的新手。
我正在尝试构建一个具有大量逻辑的组件,该组件准备数据以便能够在 HTML 中显示。
据我所知 - 这个逻辑应该从组件移动到其他地方,以免触发更改跟踪。(正如 样式指南中所说)
我这个其他地方应该是服务班还是助手班?如果它是服务,是否应该将其添加到该组件的组件模块的“提供者”中,还是添加到组件本身的“提供者”中?
@Component({
selector: 'filters-bar',
templateUrl: './filters-bar.component.html',
styleUrls: ['./filters-bar.component.scss'],
providers:[FiltersFromQueryService]
})
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在尝试通过序列化和反序列化来创建我的ViewModel对象的副本:
var copyOfObj= ko.mapping.fromJSON(ko.toJSON(myViewModel))
Run Code Online (Sandbox Code Playgroud)
如果我对对象进行一些操作,我会得到以下错误:
未捕获的TypeError:在无法选择的输入元素上访问selectionDirection.
希望有人能够解释我这个问题
谢谢
PS现在我开始认为它与编辑对话框表单有关,输入绑定到此视图模型的值
我正在使用网格,一切都很完美:我可以更新删除和添加行,并且更改正在立即更新,但我的寻呼机有问题:即使在示例页面 http://rniemeyer.github.com/knockout-剑道/网络/ Grid.html
,当网格中的记录少于一个pageSize时:寻呼机上的消息是:"NaN - 3个项目的NaN"(这是错误的,它必须像"3个项目中的1 - 1")是解决方法的任何解决方法这个小问题?
谢谢你
angular ×4
knockout.js ×3
angularjs ×2
animation ×1
css ×1
jquery ×1
jquery-1.9 ×1
json ×1
kendo-ui ×1
knockout-2.0 ×1
ngrx ×1
rxjs ×1