directive

AngularJS Form Validation Directive $setValidity on element

匿名 (未验证) 提交于 2019-12-03 01:06:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to use $setValidity on an element in a directive. All the examples I've found seem to set it on the controller... I forked a JS fiddle on Form Validation and have tried a bunch of things. Any insights would be most appreciated: http://jsfiddle.net/thomporter/pmKpG/2/ In the fiddle, the $setValidity is called on the controller: ctrl.$setValidity('pwd', true); I'd like to do something like: elm.$setValidity('pwd', true); so that in the form I can do something like: ng-class="{error:form.password.$error.pwd}" 回答1: I figured it out...

AngularJS directive to scroll to a given item

匿名 (未验证) 提交于 2019-12-03 00:59:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a scope variable $scope.first_unread_id which is defined in my controller. In my template, I have: {{ item.content }} and my directive looks like: angular.module('ScrollToId', []). directive('scrollToId', function () { return function (scope, element, attributes) { var id = scope.$parent[attributes["scrollToId"]]; if (id === scope.item.id) { setTimeout(function () { window.scrollTo(0, element[0].offsetTop - 100) }, 20); } } }); it works, however, two questions: Is there a better way of getting the "first_unread_id" off the controller

AngularJS directive $watch two-way binding

匿名 (未验证) 提交于 2019-12-03 00:50:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to distinguish between internal change and an external change with a two-way data-bound attribute ( '=' ). In other words: I don't want to $watch to fire on the value if the change was internal (i.e. the scope variable was changed in the controller or in the link function). Here some code that illustrates my problem: HTML <div ng-app="myApp"> <div ng-controller="MainCtrl"> <input ng-model="value"/> <mydemo value="value"></mydemo> </div> </div> Javascript app.directive('mydemo', function () { return { restrict: 'E', scope: { value:

angular directive 深入理解

匿名 (未验证) 提交于 2019-12-03 00:38:01
由于业务的需要,最近angular 的diretive 研究的比较多,有和同事一起共同协作开发scada的项目, 对directive 有了进一步更深的理解。 感觉才开始真正理解了这句话的意思: In an AngularJS directive the scope allows you to access the data in the attributes of the element to which the directive is applied 这句话,感觉道出了diretive的原理的精髓。 -------------------------------------------------------------------------------------------------------------------- > < @ {{}} = & When we are setting scope: true in directive, Angular js will create a new scope for that directive. That means any changes made to the directive scope will not reflect back in parent controller. ----------------

java.lang.IllegalArgumentException: Page directive: invalid value for import

匿名 (未验证) 提交于 2019-12-02 21:53:52
原文地址为: java.lang.IllegalArgumentException: Page directive: invalid value for import 我的项目原来用的tomcat版本是apache-tomcat-7.0.53,后来为了安全原因将版本升至\apache-tomcat-7.0.57,发现有的jsp页面出现下面的异常: java.lang.IllegalArgumentException: Page directive: invalid value for import 仔细检查发现是<%@ page import=" java.util.*;"%>一句引起的错误。把<%@ page import=" java.util.*;"%>中的分号去掉就好了,改为: <%@ page import=" java.util.*"%> 所以以后写import要规范。项目中可能还有多处这种问题,大部分情况是开发人员写代码太随意的原因。 转载请注明本文地址: java.lang.IllegalArgumentException: Page directive: invalid value for import 文章来源: java.lang.IllegalArgumentException: Page directive: invalid value for

Angularjs: how to pass scope variables to a directive?

有些话、适合烂在心里 提交于 2019-12-02 18:57:40
I am trying to use directive to create and append several tags to a <div> as shown below: module.directive('createControl', function(){ return function(scope, element, attrs){ console.log(attrs.createControl); // undefined } }); <div class="control-group" ng-repeat="(k, v) in selectedControls"> <div create-control="{{ v.type }}"></div> </div> In attrs I have this construction: $$element: b.fn.b.init[1] $$observers: Object $attr: Object createControl: "date" style: "margin-right: 15px" __proto__: Object But when I try to use attrs.createControl I get undefined and I do not understand why.

vue基础----自定义组件directive ,bind,update,insert

半腔热情 提交于 2019-12-02 16:35:47
<div id="app"> <input type="text" v-limit.3="msg" v-focus> </div> <script src="./node_modules/vue/dist/vue.js"></script> <script> Vue.directive("focus",{ /* 方法一*/ /* bind(el){ Vue.nextTick(function(){ // 在dom元素执行完之后执行 el.focus(); }); }*/ /* 方法二 */ inserted(el){ //绑定元素插入父节点时调用 el.focus(); } }); Vue.directive("limit",function(el,bindings,vnode){ /* el:元素 bindings:元素绑定的值 vue dom的更新是异步的 */ console.log(el); console.log(bindings); console.log(vnode); let [,len] = bindings.rawName.split("."); /*思想就是 把在文本框输入的值手动改到虚拟dom中,在虚拟dom 中改变 vlaue的值*/ let ctx = vnode.context; el.addEventListener("input",(e)=>{

How to pass filter to a directive in AngularJS

℡╲_俬逩灬. 提交于 2019-12-02 03:15:39
I have a custom directive and I want to be able to pass a filter name to it. That filter will then be use in my template. Here is what I got so far: the directive: angular.module('forecastDirective', []) .directive('forecast', ['appConfig', function(appConfig) { return { templateUrl: appConfig.directivesRoot + 'templates/forecast.html', replace: true, scope: { weatherObject: "=", convertToDate: "&", filterTemp: "@", dateFormat: "@", }, } }]); The template: <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">{{ convertToDate({ dt: weatherObject.dt }) | date:

Change Detect not working in directive event ouput in Angular 2

若如初见. 提交于 2019-12-02 02:19:23
I use this directive. However, on the setAddress event output, no changes are detected in my component. The view is not updated. I d'ont understand. For test, if i remove the google.maps.event.addListener to replace by a simple setTimeout to call invokeEvent. It works. @Directive({ selector: '[googleplace]', providers: [NgModel], host: { '(input)' : 'onInputChange()' } }) export class GoogleplaceDirective { @Output() setAddress: EventEmitter<any> = new EventEmitter(); modelValue:any; autocomplete:any; private _el:HTMLElement; constructor(el: ElementRef,private model:NgModel) { this._el = el

How to access controllerAs namespace in unit test with compiled element?

流过昼夜 提交于 2019-12-01 18:58:43
In this fiddle http://jsfiddle.net/FlavorScape/fp1kktt9/ i try to set properties on the controller, not the $scope directly. In the template (in production) we just do myAliasCtrl.somePropertyList and the ng-repeat works. However, this does not work in testing. I don't know how to get/assign the property on the controller. UPDATE: I must have had some weird localized issue in my testing environment, because i do get ng-repeat to work. notice how there's two child elements, even though the property is on the aliased controller. http://jsfiddle.net/FlavorScape/2adn983y/2/ however, my question