简体   繁体   English

在给定的工作流程中,angularjs和指令的最佳实践是什么?

[英]What is the best practice for angularjs and directives in the given workflow?

We have created a three window wizard. 我们创建了一个三窗口向导。 They are all three divs on the same page (or could be broken into partials if a better solution presents itself). 它们都是同一页上的所有三个div(如果可以提供更好的解决方案,也可以将其划分为多个部分)。 We use jquery's fadein/out to transition through the wizard's divs. 我们使用jQuery的fadein / out来过渡向导的div。 They all share some data objects they must all be aware of during the wizard. 它们都共享一些必须在向导过程中注意的数据对象。 The second window is simply a "One Moment Please" waiting on a callback from an ajax call before transitioning to the third window. 第二个窗口只是一个“ One Moment Please”,正在等待ajax调用的回调,然后过渡到第三个窗口。

We have loaded the fadein/out into a directive and it works. 我们已经将fadein / out加载到指令中,并且可以正常工作。 The issue is we track the state of the DOM elements in the controller with a 'flag'. 问题是我们使用“标志”跟踪控制器中DOM元素的状态。

$scope.someDomId == 'visible' or 'hidden'. $ scope.someDomId =='可见'或'隐藏'。

The directive watches for changes on said id and takes appropriate action if its changed. 该指令监视所述id的更改,如果更改则采取适当的措施。

This works, but it seems ugly to me. 这可行,但是对我来说似乎很难看。 True we have removed Dom manipulation from the controller, but replaced it with a gross flagging system. 没错,我们已经从控制器中删除了Dom操纵,但是将其替换为总标记系统。

Is this the best practice? 这是最佳做法吗? Is this really better? 这真的更好吗? Yes it can be unit tested more easily now, but that is the only perceived benefit I see at this point. 是的,现在可以更轻松地对其进行单元测试,但这是我在这一点上唯一看到的好处。

You can have situation with several directives on one page related to one flag variable in controller. 您可能会在一页上遇到几种与控制器中的一个标志变量相关的指令。 And they will work separately this way. 他们将以这种方式分别工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM