- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
公众号:https://plnkr.co/edit/Brmcxd2LjGVJ6DXwuJtF?p=preview
$login
-> $container
(包含 $dashboard
和 $feed
),dashboard
包含:$tickers
, $tags
, $viewHeader
和 $socialMedia
组件。
tags
需要通信并将标记对象发送到 viewHeader
和 socialMedia
州。
登录后,在标签列表中选择一个按钮应该发送tag
进入 ViewHeader 和 SocialMedia 状态/组件。
登录后,在标签中选择一个按钮并转到 $state dashboard
ViewHeader 和 SocialMedia 的 $states 刷新但 View 模型变量 {{ term }}
未使用任一组件中的适当标记进行更新。
我试图通过混合使用状态、组件、同级组件和 View 来解决的问题是,当任何状态发生变化时,应用程序中的每个组件总是刷新/重新启动。 $state.go('dashboard'...
这并不理想,我想要的是确保只有需要刷新的组件才刷新。
IE:当我选择一个 Ticker 或一个 Tag 时,我不希望 Feed 组件每次都刷新。但是,用户应该能够在 Feed 组件中执行操作,它会更新所有其他组件。
这就是我创建 container
的原因状态同时持有 dashboard
和 feed
状态。最初我在 dashboard
中拥有一切状态,随时$state.go('dashboard'
发生了 feed
组件也会刷新。如果有更好的办法解决这个问题lmk! :)
PS:开始学习使用 ui-router 进行状态管理,以消除对 $rootScope 的依赖。到目前为止,我的真实应用程序要稳定得多,但是有一个令人讨厌的功能,即每个组件都会刷新/重新启动。
在下面的截图中我可以清楚地看到正确的 tag
正在传递到正确的 $states,但是 {{ term }}
不更新。
代码片段(Plnkr 中的完整代码)
app.container.html(容器状态)
<div>
<dashboard-module></dashboard-module>
<feed-module></feed-module>
<!--<div ui-view="dashboard"></div>-->
<!--<div ui-view="feed"></div>-->
</div>
dashboard.html(仪表板状态)
<div class="jumbotron text-center">
<h1>The Dashboard</h1>
</div>
<div class="row">
<tickers-module></tickers-module>
<!-- Tags component goes here -->
<div ui-view></div>
<view-module></view-module>
<social-module></social-module>
</div>
^ 我使用 <div ui-view>
的原因上面加载标签状态是迄今为止我可以初始化标签模块并显示代码组件中的标签列表的唯一方法。
代码组件 Controller :
tickers.component('tickersModule', {
templateUrl: 'tickers-module-template.html',
controller: function($scope, $state) {
console.log('Tickers component', $state.params);
$scope.tickers = [
{ id: 1, ticker: 'AAPL' },
{ id: 2, ticker: 'GOOG' },
{ id: 3, ticker: 'TWTR' }
];
$state.go('tags', { ticker: $scope.tickers[0] }); // <---
$scope.clickTicker = function(ticker) {
$state.go('tags', { ticker: ticker });
}
}
^ <--- 上面允许标签状态加载标签组件元素并连接标签列表,基于代码的状态
var tags = angular.module('tags', ['ui.router'])
tags.config(function($stateProvider) {
const tags = {
parent: 'container',
name: 'tags',
url: '/tags',
params: {
ticker: {}
},
template: '<tags-module></tags-module>',
controller: function($scope, $state) {
console.log('Tags state', $state.params);
}
}
$stateProvider.state(tags);
})
tags.component('tagsModule', {
templateUrl: 'tags-module-template.html',
controller: function($scope, $state) {
console.log('Tags component', $state.params);
const tags_model = [
{
ticker: 'AAPL',
tags : [{ id: 1, term: 'iPhone 7' }, { id: 2, term: 'iPhone 8' }, { id: 3, term: 'Tim Cook' }]
},
{
ticker: 'GOOG',
tags : [{ id: 4, term: 'Pixel' }, { id: 5, term: 'Pixel XL' }, { id: 6, term: 'Chrome Book' }]
},
{
ticker: 'TWTR',
tags : [{ id: 7, term: 'tweet' }, { id: 8, term: 'retweet' }, { id: 9, term: 'moments' }]
}
];
function matchTags(ticker, model) {
return model.filter(function(obj){
if (obj.ticker === ticker) { return obj; }
});
}
$state.params.ticker = $state.params.ticker || {};
$scope.tags_model = matchTags($state.params.ticker.ticker, tags_model)[0];
$scope.clickTag = function(tag) {
console.log(' Tag clicked', $state);
$state.go('dashboard', { tag: tag });
}
}
});
标签列表中的点击功能:
$scope.clickTag = function(tag) {
console.log(' Tag clicked', $state);
$state.go('dashboard', { tag: tag });
}
社交媒体 Controller :
social.component('socialModule', {
templateUrl: 'social-module-template.html',
controller: function($scope, $state) {
console.log('Social component', $state.params);
$scope.term = $state.params.tag.term;
}
});
viewHeader Controller :
view.component('viewModule', {
templateUrl: 'view-module-template.html',
controller: function($scope, $state) {
console.log('View component', $state.params);
$scope.term = $state.params.tag.term;
}
});
刚刚注意到这一点,在点击一个标签并进入 social.component 内部之后。看起来仪表板组件正在重新呈现以代替标签组件一瞬间:
{ refresh: true }
解决了这里的问题到 $state.go 标签。但是请注意,这仍然没有解决我最初的任务,即阻止 feed.component 刷新。所以最终会使用服务。最佳答案
我已经更新了你的plunker
https://plnkr.co/edit/ywyH7wOmR6loNiAkH9Yb?p=preview
解决方案相当简单。而不是使用 $state
在依赖注入(inject)中使用 $stateParams
这是一个单例,所以如果你像我在更新的 plunker 中那样引用它:
$scope.params = $stateParams
然后是显示值
{{params.ticker.ticker}}
将以两种方式绑定(bind)到 $stateParams 并在您每次更改状态时相应地更新
---编辑---
我通过服务添加了另一个解决方案 https://plnkr.co/edit/oQNAHv7tAS8LR9njOUAX?p=preview
.service('awesomeTag', function($rootScope){
var self = this;
$rootScope.$on('$stateChangeSuccess', function(_event, _toState, toParams){
self.tag = toParams.ticker.ticker
})
})
关于javascript - 如何将 $state 变量传递给其他 2 个同级 $states?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42865321/
我正在编写一个简单的有限状态机,并意识到在某些情况下,事件可以将状态变为多个可能的结果。基本上,从状态 A,如果事件 E 发生,状态可能是 C 或 D。 我目前正在使用此处编写的 Javascript
我在 React 中构建了一个应用程序,我在其中一个样板项目中找到了一行。 (state = {}) => state 谁能给我解释一下上面这行是什么意思?它是 javascript ES6 标准。
如何将多个状态变量组合成另一个? 我想通过一些用户交互来更改高度或宽度的值,并相应地更新 View 中的所有内容。所以高度或宽度会改变,面积也会改变。 我想它看起来像这样 @State var wid
我的容器正在通过 redux store 获取状态。 我通过这样的 Prop 将这个状态传递给模态框:示例: render(){ let {team,id} =this.props.data;
您好,我正在尝试使用 map 根据我所在状态的数组渲染选项,但在返回中使用它时我得到未定义 这是数组 this.state = { countries: ["Australia","Brazil"
我想将 this.state.currentPlayer 分配给 this.state.whosPlaying。它抛出错误TypeError:无法读取新板上未定义的属性“currentPlayer”。
我正在实现某种动态工作流程,当达到某个点时,我必须重新加载状态以呈现 HTML 并重新实例化 Controller 才能继续。 我发现我第二次调用 $state.reload() 不起作用。这是期望的
我正在开发一个 flutter 应用程序,并发现状态管理出现意外行为。我创建了一个示例应用来重现该行为,您可以在下面找到代码和日志输出。 该应用程序包含一个简单的 ListView,其中包含 10 个
有人可以举一个简单的例子,其中 state monad 比直接传递 state 更好吗? bar1 (Foo x) = Foo (x + 1) 对比 bar2 :: State Foo Foo bar
我想写类似 $state.go("/spheres/{{$stateParams.sphereId}}/mono/view"); 的内容使用外部 url 而不是状态,但这不起作用:( 现在我明白为什么
我正在使用“angular-ui-tree”:“^2.22.5” 点击执行某事菜单项时出错.. TypeError: this.$state is undefined 如何将对 $state 的引用传
我在elasticsearch中有文本字段,我想在kibana上可视化词云... 第一步,我们需要标记它们,我使用了“标准标记器” ... 使用这种形式的词云可视化结果如下图所示: 但是我需要的是专有
我正在尝试以编程方式在状态之间移动(使用 ui.router),而用户无需单击任何内容。文档位于 http://angular-ui.github.io/ui-router/site/#/api/ui
我想编写像“(event, state) -> state”这样的折叠函数。如果Java中没有任何模式匹配且不可变,我该如何编写它? 最佳答案 我认为您正在寻找 Java 中的函数式编程。 此版本中引
这个问题已经有答案了: What does an exclamation mark before a variable mean in JavaScript (4 个回答) 已关闭 8 年前。 您好,
https://plnkr.co/edit/bOZW1a9u62W1QA6cYjYj?p=preview 预期 登录后,所有 $states 都会初始化,然后单击 Ticker 按钮后,唯一应重新初始
试图决定(针对我的应用程序)在 onPause() 中保存什么以及要保存在 onSaveInstanceState() 中的内容,我梳理了整个 SO 以获得提示和明确的指导方针。 如果我没理解错的话,
在 Javascript 中,当我单击滚动条(页面中出现的任何滚动条)并将鼠标悬停在图像上时,图像再次开始拖动。 图像只能在鼠标按钮按下状态下拖动。 所以我试图通过了解鼠标按钮状态(mousedown
我见过 Maybe和 Either在代码中使用仿函数(和应用)是有道理的,但我很难想出一个 State 的例子。仿函数和应用。也许它们不是很有用,只是因为 State 才存在。 monad 需要一个仿
我非常努力地想围绕 State Monad,但我不明白以下内容: 鉴于 return 的实现和 (>>=) ,当你说 State $ \s ->.... ,在哪里s来自?我的意思是,当你开始表演时 >
我是一名优秀的程序员,十分优秀!