角色开始时我有一个任务:
- name: check if pg_* variables are defined
fail: msg="variable {{item}} is undefined"
when: "{{item}} is undefined"
with_items:
- pg_dbname
- pg_host
- pg_port
- pg_username
- pg_password
Run Code Online (Sandbox Code Playgroud)
但是较新版本的Ansible发出以下警告:
[警告]:当语句不应包含jinja2模板分隔符时,例如{{}}或{%%}。找到:{{item}}未定义
删除Jinja2括号when: item is undefined不起作用,因为最终评估结果基本上等同于:
"pg_dbname" is undefined` # False
"pg_host" is undefined` # False
.
.
"pg_password" is undefined` # False
Run Code Online (Sandbox Code Playgroud)
这不是我想要的。
我使用该$modal.open({...})方法打开UI-Bootstrap模式.当用户按下后退按钮时,我需要关闭它.
在这种情况下result,该open()方法返回的promise 无用,因为它无法检测由于后退按钮导致的状态更改.现在,当按下后退按钮时,状态会发生变化,但模态会保持打开状态.
基本上我有这个问题的确切问题,但即使它有一个选定的答案,问题也没有解决,从评论中可以看出.这个问题类似,但也没有解决后退按钮问题.
我需要一些方法来检测当前状态是否已从控制器和调用$modalInstance.close()或$scope.$close()方法中发生变化.
我可以监听$stateChangeStart事件并检查fromState参数以有条件地关闭模态.但是,此事件也将不必要地继续为所有后续状态更改而触发.
更新:所以我试着听一下这个事件,并在第一次被解雇时立即取消注册.这样我就可以听到后退按钮状态的变化,然后在我想要的时候停止它.模态的最终代码如下:
$stateProvider.state('itemList.itemNew', {
url: '/new',
onEnter: function($state, $modal) {
$modal.open({
templateUrl: "/static/partials/item/form.html",
controller: function($http, $scope, $modalInstance) {
$scope.editableItem = {};
$scope.saveItem = function(item) {
$http.post('/api/item', item)
.success(function(data) {
$modalInstance.close(data);
alert("Saved Successfully");
}).error(function(data) {
alert("There was an error.");
});
};
//Register listener specifically for the back button :(
deRegister = $scope.$on('$stateChangeSuccess',
function(event, …Run Code Online (Sandbox Code Playgroud)