使用ui-router的命名视图转换
Named view transition using ui-router
是否有可能在ui-router中的命名视图过渡到其他命名视图?
例如,在下面的代码片段中,是否有可能从blue@bar
状态移动到orange@foo
状态?
.state('foo', {
url: '/',
views: {
'': { templateUrl: 'partials/a.html' },
'black@foo': {
templateUrl: 'partials/b.html',
controller: 'SuperController'
},
'green@foo': {
templateUrl: 'partials/c.html',
controller: 'SuperController'
},
'orange@foo': {
templateUrl: 'partials/d.html',
controller: 'SuperController'
}
}
})
.state('bar', {
url: '/ping/:x/:y',
views: {
'': {
templateUrl: 'partials/e.html',
controller: 'DuperController'
},
'blue@bar': {
templateUrl: 'partials/f.html',
controller: 'DuperController'
}
}
})
ui-router
过渡存在于state transitions
。换句话说,视图之间没有转换。
ui-view="myName"
)到根或一些父状态。然后,每个子(孙子)状态可以针对其父(s)层次结构中的任何命名视图。
最好的理解方法是阅读doc:
中的这一章。视图名称-相对名称与绝对名称
检查下面的代码片段(引用自上面的资源):
$stateProvider
.state('contacts', {
// This will get automatically plugged into the unnamed ui-view
// of the parent state template. Since this is a top level state,
// its parent state template is index.html.
templateUrl: 'contacts.html'
})
.state('contacts.detail', {
views: {
////////////////////////////////////
// Relative Targeting //
// Targets parent state ui-view's //
////////////////////////////////////
// Relatively targets the 'detail' view in this state's parent state, 'contacts'.
// <div ui-view='detail'/> within contacts.html
"detail" : { },
// Relatively targets the unnamed view in this state's parent state, 'contacts'.
// <div ui-view/> within contacts.html
"" : { },
///////////////////////////////////////////////////////
// Absolute Targeting using '@' //
// Targets any view within this state or an ancestor //
///////////////////////////////////////////////////////
// Absolutely targets the 'info' view in this state, 'contacts.detail'.
// <div ui-view='info'/> within contacts.detail.html
"info@contacts.detail" : { }
// Absolutely targets the 'detail' view in the 'contacts' state.
// <div ui-view='detail'/> within contacts.html
"detail@contacts" : { }
// Absolutely targets the unnamed view in parent 'contacts' state.
// <div ui-view/> within contacts.html
"@contacts" : { }
// absolutely targets the 'status' view in root unnamed state.
// <div ui-view='status'/> within index.html
"status@" : { }
// absolutely targets the unnamed view in root unnamed state.
// <div ui-view/> within index.html
"@" : { }
});
同样,检查这个示例应用(由ui-router团队)
- <
- http://angular-ui.github.io/ui-router/sample//联系人/gh>
及其状态定义
- state.js
来自子状态定义的小引用,针对许多不同的视图:
///////////////////////
// Contacts > Detail //
///////////////////////
// You can have unlimited children within a state. Here is a second child
// state within the 'contacts' parent state.
.state('contacts.detail', {
// Urls can have parameters. They can be specified like :param or {param}.
// If {} is used, then you can also specify a regex pattern that the param
// must match. The regex is written after a colon (:). Note: Don't use capture
// groups in your regex patterns, because the whole regex is wrapped again
// behind the scenes. Our pattern below will only match numbers with a length
// between 1 and 4.
// Since this state is also a child of 'contacts' its url is appended as well.
// So its url will end up being '/contacts/{contactId:[0-9]{1,8}}'. When the
// url becomes something like '/contacts/42' then this state becomes active
// and the $stateParams object becomes { contactId: 42 }.
url: '/{contactId:[0-9]{1,4}}',
// If there is more than a single ui-view in the parent template, or you would
// like to target a ui-view from even higher up the state tree, you can use the
// views object to configure multiple views. Each view can get its own template,
// controller, and resolve data.
// View names can be relative or absolute. Relative view names do not use an '@'
// symbol. They always refer to views within this state's parent template.
// Absolute view names use a '@' symbol to distinguish the view and the state.
// So 'foo@bar' means the ui-view named 'foo' within the 'bar' state's template.
views: {
// So this one is targeting the unnamed view within the parent state's template.
'': {
templateUrl: 'app/contacts/contacts.detail.html',
controller: ['$scope', '$stateParams', 'utils',
function ( $scope, $stateParams, utils) {
$scope.contact = utils.findById($scope.contacts, $stateParams.contactId);
}]
},
// This one is targeting the ui-view="hint" within the unnamed root, aka index.html.
// This shows off how you could populate *any* view within *any* ancestor state.
'hint@': {
template: 'This is contacts.detail populating the "hint" ui-view'
},
// This one is targeting the ui-view="menu" within the parent state's template.
'menuTip': {
// templateProvider is the final method for supplying a template.
// There is: template, templateUrl, and templateProvider.
templateProvider: ['$stateParams',
function ( $stateParams) {
// This is just to demonstrate that $stateParams injection works for templateProvider.
// $stateParams are the parameters for the new state we're transitioning to, even
// though the global '$stateParams' has not been updated yet.
return '<hr><small class="muted">Contact ID: ' + $stateParams.contactId + '</small>';
}]
}
}
})
其他链接
相关文章:
- 将c#视图模型转换为javascript模型时转义HTML标记
- Rails-从一个视图到下一个视图的水平转换
- 转换复选框'在'在发布到Django视图之前,将其设置为Boolean
- 在两个视图之间来回转换
- 将高图表堆叠的每日列从“日”视图转换为“月”视图
- 如何使用 JSON 在动态中转换列表视图静态
- 以数学方式转换 SVG 路径中的值以填充视图框
- 三.js 通过对象克隆将多个视图转换为多个画布.陷阱
- Ember.js-将仅显示模板转换为使用视图
- 在MVC的视图文件夹中将Razor代码转换为aspx代码
- AngularJS-转换输入值并使视图反映所做的更改
- 将三维世界矢量转换为模型视图矩阵
- 视图转换后浏览器中的旧视图或DOM元素会发生什么情况
- 使用ui-router的命名视图转换
- 将html视图转换为图像
- Backbonejs+MarionetteJD-将Backbone列表视图转换为MarionetteJS集合视图
- Cordova iOs在SAPUI5应用程序的视图转换中无故显示键盘
- 将CouchDB javascript视图转换为erlang
- Rails 3:将Rails视图转换为javascript狙击其他人可以复制/粘贴
- Dojo MVC:如何在数据错误时取消视图转换