简体   繁体   English

Ng单击和md按钮冲突

[英]Ng-click and md-button conflict

I'm having trouble getting a link inside a MD button to load content on the page normally i just use 我在使用MD按钮内的链接以正常加载页面上的内容时遇到麻烦

<a class="wordpress" href="#" ng-click="active='Wordpress'">Wordpress</a>

which then just writes the content I need with 然后只写我需要的内容

<p ng-show="active === 'Wordpress'">Find a sample of my wordpress codeing</p>

but this doesn't work with a md button it doesnt write anything despite having the same paragragh output 但这不适用于md按钮,尽管具有相同的paragragh输出,但它不会写入任何内容

<md-menu-item>
  <md-button>
    <a class="TokusatsuSeries" ng-click="active='TokusatsuSeries'">
      Tokusatsu Series/Five Year War
    </a>
  </md-button>
</md-menu-item>

<p ng-show="active === 'TokusatsuSeries'">You chose <b>{{active}}</b></p>

Edit tried the 2 suggestions the VM broke the code and CTR didn't work any better them my original: Edit尝试了VM破坏代码的2条建议,而CTR并没有比我原来的更好:

<md-menu-item>
            <md-button>
                    <a class="TokusatsuSeries" 
                       ng-click="$ctrl.active='TokusatsuSeries'">Tokusatsu Series/Five Year War
                    </a>
            </md-button>
</md-menu-item>

and the paragraph to write 和该段写

<p ng-show="$ctrl.active === 'TokusatsuSeries'">You chose <b>{{active}}</b></p>

It seems that the problem appears because one of material component creates it own scope . 似乎出现此问题是因为一种材料成分创建了自己的scope You should avoid this. 您应该避免这种情况。 If you're working with AngularJS components you should bind to $ctrl ie 如果您正在使用AngularJS组件,则应绑定到$ctrl

<md-menu-item>
    <md-button>
        <a class="TokusatsuSeries" 
           ng-click="$ctrl.active='TokusatsuSeries'">Tokusatsu Series/Five Year War
        </a>
    </md-button>
</md-menu-item>

<p ng-show="$ctrl.active === 'TokusatsuSeries'">You chose <b>{{active}}</b></p>

Otherwise, you can use controllerAs syntax 否则,您可以使用controllerAs语法

<div ng-controller="SomeController as vm">
    <md-menu-item>
        <md-button>
            <a class="TokusatsuSeries" 
               ng-click="vm.active='TokusatsuSeries'">Tokusatsu Series/Five Year War
            </a>
        </md-button>
    </md-menu-item>

    <p ng-show="vm.active === 'TokusatsuSeries'">You chose <b>{{active}}</b></p>
</div>

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

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