简体   繁体   English

不同指令的角度变化css

[英]Angular change css of different directive

I have a real problem to change some simple css with Angular and css. 我有一个真正的问题,要用Angular和CSS更改一些简单的CSS。

I have the code: 我有代码:

<div class="progress">
    <div class="progress-bar progress-bar-info" ng-class="stepOne">1</div>
    <div class="progress-bar progress-bar-info" ng-class="stepTwo">2</div>
    <div class="progress-bar progress-bar-info" ng-class="stepTree">3</div>
</div>

<div class="well col-lg-12">
    <applystepone ng-if="step.one"></applystepone>  <!-- this is my directive -->
    <applysteptwo ng-if="step.two"></applysteptwo>
    <applysteptree ng-if="step.tree"></applysteptree> 

</div>

In the directive : applystepone i have a button. 在指令:applystepone我有一个按钮。 If I click on the button i want the css of the progress bar change for ng-class="stepOne" 如果我单击按钮,我希望进度条的css更改为ng-class="stepOne"

The button in the directive : 指令中的按钮:

<div class="col-lg-12 text-center">
    <a class="btn btn-primary" ng-click="steptwo(); stepOne='valide-step'">Next step</a> 
</div>

And the directive : 和指令:

app.directive('applystepone', function() {

    return {
        restrict: 'E',
        templateUrl: 'partials/apply-step-one.html'
    };
});

If i click on the button, nothing append to the 如果我单击该按钮,则没有任何附加内容

ng-class="stepOne"

If i place in the apply-step-one.html 如果我放置在apply-step-one.html

<p ng-class="stepOne">Test </p>

The css works, so the button works fine. CSS可以正常工作,因此按钮可以正常工作。 I suppose it's because my ng-click is in the directive and not the ng-class="stepOne" . 我想这是因为我的ng-click在指令中,而不是ng-class="stepOne"

Try: 尝试:

<a class="btn btn-primary" ng-click="steptwo(); $parent.stepOne='valide-step'">Next step</a>

$parent will retrieve the parent scope from inside your directive. $ parent将从指令内部检索父作用域。

Not 100% sure I understood the whole thing, but here it goes. 不能100%地确定我理解了整个事情,但是事情已经过去了。

I think you should consider modifying your CSS (which you haven't shown, btw) and the code slightly: 我认为您应该考虑修改CSS(未显示,顺便说一句)和代码:

<div class="progress">
    <div class="progress-bar progress-bar-info" ng-class="{active: step.one}">1</div>
    <div class="progress-bar progress-bar-info" ng-class="{active: step.two}">2</div>
    <div class="progress-bar progress-bar-info" ng-class="{active: step.three}">3</div>
</div>

This would trigger the active class on your progress bar based on the step in scope. 这将根据范围中的步骤触发进度条上的active类。

Then, instead of 然后,代替

<p ng-class="stepOne">Test </p>

you should probably use something more generic like: 您可能应该使用更通用的方法,例如:

<p class="button">Test </p>

and modify the CSS to trigger it, for example: 并修改CSS以触发它,例如:

.well p.button {
    color: green;
} 

And if you just want to modify the class of the button, it's simple: 而且,如果您只想修改按钮的类,这很简单:

<p ng-class="{'stepOne': step.one, 'stepTwo': step.two, 'stepThree': step.three}">Test </p>

It's similar to what I described above, for the progress bar divs. 进度栏div类似于我上面描述的内容。

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

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