[英]Angular parent scope not updated when directive updates the same scope variable
[英]Angular directive not getting called when scope is updated
我有一个正在修改变量的范围:
$scope.showContext = function(context) {
$scope.currentContext = context;
....
}
我在页面上有一条指令:
<div org-chart workflow="currentContext" />
我有一条指令:
var OrgChartDirective = function($timeout) {
return {
restrict : 'AE',
scope : {
workflow : '=',
},
link : function(scope, element, attrs) {
if (scope.workflow != null) {
console.log("**________________________________**");
console.log(scope);
} else {
alert("Workflow is null");
}
....
加载页面时,我收到工作流为空的警报。
当我运行更新$scope.currentContext
的作用域函数时,没有任何其他反应。 应该再次调用吧?
编辑说:我在页面上有这个,它确实表明在调用scope方法后变量已被设置:
工作流程----> {{currentContext.workflow}}
视查理菲为准,与观察者一起尝试
link : function(scope, element, attrs) {
scope.$watch('workflow', function(val) {
...
});
您将必须在链接函数中观察/观察属性变化,如下所示:
attrs.$watch('workflow', function() {
//do whatever logic you want
});
在此处详细了解观察者和观察者以及如何使用它们: Ben naddal关于观察者和观察者的教程
尝试以下要点: 观察者和观察者的要点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.