简体   繁体   English

AngularJS主题颜色选择器问题

[英]AngularJS theme color picker issue

http://codepen.io/anon/pen/MJbagW http://codepen.io/anon/pen/MJbagW

In the above codepen , i have the theme color picker and it changes the color based on the button clicked. 在上面的codepen中,我有主题颜色选择器,它根据单击的按钮更改颜色。

Issue: i was wondering if it could be changed into this scenario , you pass the color you wan through directive as a parameter 问题:我想知道是否可以将其更改为这种情况,您通过指令传递想要的颜色作为参数

For example: 例如:

<my-application color="blue"></my-application>

So in this case, the word blue would be taken in the directive and then the blue theme would be applied to the application. 因此,在这种情况下,指令中将使用蓝色一词 ,然后将蓝色主题应用于该应用程序。 I wonder if this is possible? 我想知道这是否可能?

I need this as I want to change the color of my directive I just created based on user's needs. 我需要它,因为我想根据用户的需要更改刚创建的指令的颜色。

Question: Is my question above workable ? 问题:我上面的问题可行吗? Or is there another way i could change the color of the angular theme through passing in parameters only. 还是有另一种方法,我可以仅通过传入参数来更改角度主题的颜色。

In your example you can see that the directive "themePreview" already takes parameters: 在您的示例中,您可以看到指令“ themePreview”已经带有参数:

<theme-preview primary="primary" accent="accent"></theme-preview>

It takes the primary and accent color passed in the attributes, you can copy that behavior in your application. 它采用在属性中传递的主色和强调色,您可以在应用程序中复制该行为。

Example: 例:

In the codepen, change the attributes color: 在Codepen中,更改属性颜色:

<theme-preview primary="'purple'" accent="'yellow'"></theme-preview>

Since the example directive is using two-way binding, you have to single quote strings. 由于示例指令使用双向绑定,因此必须使用单引号字符串。

Or you can change to text binding @ : 或者您可以更改为文本绑定@

Directive 指示

{
  restrict: 'E',
  templateUrl: 'themePreview.tmpl.html',
  scope: {
  primary: '@',   //<--- Text binding
  accent:  '@'    //<--- Text binding
  }
}

Html HTML

<theme-preview primary="purple" accent="yellow"></theme-preview>

You can look for information on Isolate Scope and Local Scope Properties to have a clear understanding of what you want to achieve. 您可以查找有关“ 隔离范围”和“ 本地范围属性”的信息 ,以清楚地了解要实现的目标。 Try reading this blog post . 尝试阅读此博客文章

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

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