首先是一些背景:我的应用程序允许用户通过管理工具控制是否需要、禁用字段等。我有一个服务,它接受一个字段名称并以如下格式返回用户定义的规则:
{
"disabled" : true,
"required" : true
}
Run Code Online (Sandbox Code Playgroud)
我想要一个自定义属性指令,它将使用该服务控制输入字段上的这些属性。我希望用法看起来像这样:
<input type="text" my-rule="fieldName" ng-model="myfield" />
Run Code Online (Sandbox Code Playgroud)
我可以使用如下指令轻松完成此操作:
angular.module('app').directive('myRule', ['$http',
function($http) {
return {
restrict: 'A',
scope: {
myRule: '@'
},
link: function(scope, element, attrs) {
$http.get('/api/rule/'+scope.myRule).success(function(rule) {
if (rule.disabled) {
element.attr('disabled','disabled');
}
if (rule.required) {
element.attr('required','required');
}
});
}
}
}
]);
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果用户没有禁用某个字段,我可能仍想禁用它,直到例如填写另一个字段。这应该很容易做到ng-disabled
:
<input type="text" my-rule="fieldA" ng-model="fieldA" />
<input type="text" my-rule="fieldB" ng-model="fieldB" ng-disabled="!fieldA" />
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用,因为如果用户选择禁用,fieldB
则无论ng-disabled
属性如何,都应始终禁用该字段,但该ng-disabled
属性会覆盖用户的规则。我尝试了这样的方法来删除ng-disabled
用户是否禁用了该字段,但这似乎没有效果:
angular.module('app').directive('myRule', ['$http',
function($http) {
return { …
Run Code Online (Sandbox Code Playgroud) 我尝试使用phantomjs-maven-plugin来安装phantomjs二进制文件.我想在Tomcat7服务器上运行我的测试,这就是我需要自动配置二进制文件的原因.
这是我的pom.xml
<properties>
<ghostdriver.version>1.2.0</ghostdriver.version>
<phantomjs.version>1.9.7</phantomjs.version>
<phantomjs-maven-plugin.version>0.7</phantomjs-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.47.1</version>
</dependency>
<dependency>
<groupId>com.github.detro</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>${ghostdriver.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<!-- if your container implements Servlet API older than 3.0, use "jersey-container-servlet-core" -->
<artifactId>jersey-container-servlet</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.21</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.21</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>com.github.klieber</groupId>
<artifactId>phantomjs-maven-plugin</artifactId>
<version>${phantomjs-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
<configuration>
<version>1.9.7</version>
</configuration> …
Run Code Online (Sandbox Code Playgroud) java maven phantomjs selenium-webdriver phantomjs-maven-plugin