此处将为大家介绍关于当多个配置文件不活动时,如何有条件地声明Bean?的详细内容,并且为您解答有关多配置文件读取方式的相关问题,此外,我们还将为您介绍关于Angular4:如何有条件地应用指令?、an
此处将为大家介绍关于当多个配置文件不活动时,如何有条件地声明Bean?的详细内容,并且为您解答有关多配置文件读取方式的相关问题,此外,我们还将为您介绍关于Angular 4:如何有条件地应用指令?、angular – 如何有条件地禁用客户端、Angular 如何有条件地更改 css 类?、AngularJS指令 – 如何有条件地应用模板?的有用信息。
本文目录一览:- 当多个配置文件不活动时,如何有条件地声明Bean?(多配置文件读取方式)
- Angular 4:如何有条件地应用指令?
- angular – 如何有条件地禁用客户端
- Angular 如何有条件地更改 css 类?
- AngularJS指令 – 如何有条件地应用模板?
当多个配置文件不活动时,如何有条件地声明Bean?(多配置文件读取方式)
在我的Spring-Boot-App中,我想根据(未加载的)spring-profiles有条件地声明一个Bean。
条件:
Profile "a" NOT loaded AND Profile "b" NOT loaded
到目前为止,我的解决方案(有效):
@Bean@ConditionalOnExpression("#{!environment.getProperty(''spring.profiles.active'').contains(''a'') && !environment.getProperty(''spring.profiles.active'').contains(''b'')}") public MyBean myBean(){/*...*/}
有没有更优雅(更短)的方式来解释这种情况?
特别是我想在这里摆脱Spring Expression Language的使用。
答案1
小编典典从Spring 5.1.4(Spring Boot 2.1.2中包含)开始,可以在配置文件字符串注释内使用配置文件表达式。所以:
在Spring 5.1.4(Spring Boot 2.1.2)及更高版本中,它很简单:
@Component@Profile("!a & !b")public class MyComponent {}
Angular 4:如何有条件地应用指令?
我想仅在某些条件成立时才应用此指令.
例如:
<button md-raised-button="true"></button>
另一个例子:
我在plunker中创建了一个基本的动态反应形式.
我正在使用反应形式的formArrayName指令来控制数组.
我想仅在特定条件变为true时才应用formArrayName指令.否则不要添加formArrayName指令.我尝试和研究了很多,但可以找到任何解决方案.
这是plunker链接:https://plnkr.co/edit/oPZ7PyBSf8jjYa2KVh4J?p=preview
我真的很感激任何贡献.
提前致谢!
<button *ngIf="!condition"></button> <button *ngIf="condition" md-raised-button></button>
编辑:也许this会有所帮助.
angular – 如何有条件地禁用客户端
这工作正常,但是当客户端接管时有一些闪烁,我认为这是由于主块完成加载后的JS块加载.
鉴于此页面只包含静态链接和一个routerLink,根本不需要客户端,我想知道是否有办法在某些URL上禁用客户端
编辑:正如评论中建议的那样,我试图有条件地引导应用程序.我不能将URL用作条件,因为服务器对不存在的URL响应404(此时没有重定向).因此,最适合使用的是我在服务器端成功设置的TransferState,它在关闭正文标记之前生成一些输出.
不幸的是我没有找到任何方法在main.ts中正确实例化TransferState,因为它应该通过browserTransferStateModule导入,我看不到在main.ts文件中导入Angular模块的可行方法.
我尝试使用initTransferState函数直接实例化它,但它似乎不是设计为在模块外部使用,因为我收到一个错误:
ERROR in ./src/main.ts Module not found: Error: Can't resolve '@angular/platform-browser/src/browser/transfer_state' in 'G:\Documents\Projets\Myapp\Sources\master\frontend\src'
除了做一些肮脏的反序列化之外的任何想法?
解决方法
import { Injectable,Inject,PLATFORM_ID } from '@angular/core'; import { isPlatformbrowser } from '@angular/common'; export class MyComponent implements OnInit{ constructor(@Inject(PLATFORM_ID) private platform: any) { } ngOnInit() { if (isPlatformbrowser(this.platform)) { // use clientside stuff } } }
Angular 如何有条件地更改 css 类?
如何解决Angular 如何有条件地更改 css 类??
我有一个默认类的图标,类名是 card-icon ,现在我如何根据条件更改类或禁用类?
因为当条件满足或条件为真时,图标的默认颜色现在是灰色的,我想将其更改为黑色。
条件如下,当条件为真时禁用或者如果无法禁用则替换新类,例如 [class.newclass] 。
知道如何实施这些家伙吗?谢谢。
#带有默认类的图标
<mat-icon>group</mat-icon>
#条件
<mat-icon[class.newclass]="currentTabElement === ''group''">group</mat-icon>
解决方法
您可以使用 angular 中的 ng class
属性在 CSS 类之间切换作为示例,如果我想创建一个需要在深色背景和浅色背景之间切换的切换按钮,我可以进行以下更改。
HTML 文件<div [ngClass]="{''black-background'':blacked,''white-background'':!blacked}">
CSS / SCSS 文件
.black-background {
background-color: #000;
}
.white-background {
background-color: #FFF;
}
TypeScript 文件
在打字稿文件中,您需要具有我们在 HTML 标记中传递的属性 blacked
值需要是 true
或 false
blacked = true;
目前,blacked
值为 true,因此 black-background
值为 true
,因此现在我们可以看到黑色背景。如果属性 blacked=false;
,则 white-background
值为 true
,因为我们传递了 white-background:!blacked
。这样我们就可以在 CSS 类之间切换。
使用ngClass。
<mat-icon [ngClass]="{''card-icon'': true,''active-icon'': currentTabElement === ''group''}">group</mat-icon>
上面的代码将card-icon
类添加到所有图标,并且active-icon
类仅当条件currentTabElement === ''group''
评估为真。
AngularJS指令 – 如何有条件地应用模板?
考虑以下指令:
angular.module('MyApp').directive('maybeLink',function() { return { replace: true,scope: { maybeLink: '=',maybeLinkText: '=' },template: '<span>' + ' <span ng-hide="maybeLink" ng-bind-html="text"></span>' + ' <a ng-show="maybeLink" href="#" ng-bind-html="text"></a>' + '</span>',controller: function($scope) { $scope.text = $scope.maybeLinkText.replace(/\n/g,'<br>'); } }; });
该指令会将< span>和< a>到DOM(每次只有一个可见)。
如何重写指令,使其将添加 到DOM,但不是两者?
更新
OK,我想我可以使用ng-如果这样:
template: '<span>' + ' <span ng-if="!maybeLink" ng-bind-html="text"></span>' + ' <a ng-if="maybeLink" href="#" ng-bind-html="text"></a>' + '</span>'
但是,如何摆脱周围的< span>在这种情况下?
更新2
这里是使用$ compile的指令的版本。它没有周围的< span>,但双向数据绑定也不工作。我真的很感兴趣,知道如何解决双向数据绑定问题。有任何想法吗?
DEMO
angular.module('MyApp').directive('maybeLink',function($compile) { return { scope: { maybeLink: '=',link: function(scope,element,attrs) { scope.text = scope.maybeLinkText.replace(/\n/g,'<br>'); if (scope.maybeLink) { element.replaceWith($compile('<a href="#" ng-bind-html="text"></a>')(scope)); } else { element.replaceWith($compile('<span ng-bind-html="text"></span>')(scope)); } } }; });
You can specify template as a string representing the template or as a function which takes two arguments tElement and tAttrs (described in the compile function api below) and returns a string value representing the template.
function resolveTemplate(tElement,tAttrs) { } angular.module('MyApp').directive('maybeLink',function() { return { //... template: resolveTemplate,//... }; });
今天的关于当多个配置文件不活动时,如何有条件地声明Bean?和多配置文件读取方式的分享已经结束,谢谢您的关注,如果想了解更多关于Angular 4:如何有条件地应用指令?、angular – 如何有条件地禁用客户端、Angular 如何有条件地更改 css 类?、AngularJS指令 – 如何有条件地应用模板?的相关知识,请在本站进行查询。
本文标签: