我们正在使用Angularjs开发单页应用程序e-learning,并且我们需要跟踪某些组件是否“可完成”,如果它们完成。向应用程序添加存储状态的'角度方式'
不幸的是,我几乎可以肯定,我对Angularjs概念的理解是有缺陷的,所以在摆脱一些鞋角解决方案之前,我想知道实现这一点的'角度方式'是什么。
我已经将一个自定义属性指令'eng-completable'添加到组件的HTML模板(按钮单击时显示的弹出窗口)。我还可以添加一个(潜在虚假)NG-模型=“完成”变量声明......(下面第一行是有关的一个 - 其他都工作正常)
<div eng-completable ng-model="completed" class="hidden popup {{component.popup.type}}" id="{{component.popup.name}}" data-replaces="{{component.popup.replaces}}">
<div ng-if="component.popup.type=='overlay'">
<div class="float-right button close-button">X</div>
</div>
<p class="heading">{{component.popup.heading}}</p>
<div class="popup-content">
<div ng-if="0" ng-repeat-start="(innerIndex, component) in component.popup.popup_components"></div>
<div ng-if="0" ng-repeat-start="(type, object) in component"></div>
<div ng-attr-id="{{'p' + pageId + '-s' + skey + '-c' + ckey + '-component-' + index + '-innerComponent-' + innerIndex}}" ng-switch="type">
<div ng-switch-when="image" eng-image></div>
<div ng-switch-when="paragraph" eng-paragraph></div>
</div>
<div ng-if="0" ng-repeat-end></div>
<div ng-if="0" ng-repeat-end></div>
</div>
</div>
我已经添加了相应的指令到我们的app.js文件:
app.directive('engCompletable', function() {
return {
restrict: 'A',
link: function(scope, element, attrs) {
scope.completed = false;
console.log("completable attribute encountered and triggered: scope.completed = "+scope.completed);
}
}
});
但那又怎样?如何从“全局”的角度访问已完成的变量?下一步似乎并不明显的事实表明我已经出错了。
在角度应用程序中存储和跟踪多个完成变量(在多个范围内?)的最佳方式是什么?
编辑
我想我可能需要包括更多的细节,真正显示我的问题:
假设我能在“completable”属性添加到每个CHI-completable指令的范围,当用户单击触发相应弹出组件的按钮组件(通过对DOM元素的id引用)时,如何引用弹出组件的角度范围来更改“completable”属性?
我明白,即使问题的框架可能有缺陷,但如果是这样,我想知道什么是“正确”的方式来做到这一点,在角度。
谢谢。
你只想知道一件事情是完成还是多次? 你还想要触发多少东西? – RyanDawkins
每个应用程序会有任何数量的补充。我们刚刚添加了第一个交互组件(一个弹出窗口和相应的按钮),但会有更多类型的可完成组件,并且它们可能会在应用程序中多次出现。 – moosefetcher