AngularJS Directives check for flag -
i have question angularjs directives. have following directive- code:
<div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title"> <div class="badge pull-right" tooltip="role" tooltip-append-to-body="true" editable-text="vm.mytext">{{vm.mytext}}</div> ...
and in code there
editable-text="vm.mytext"
but use directive lot of times don't need edit
... div class="badge pull-right" tooltip="role" ...
every time. use directive this:
<div ng-repeat="item in items"> <as-directive-name item="item"></as-directive-name> </div>
my question if possible user directive this:
<div ng-repeat="item in items"> <as-directive-name item="item" roleeditable="false"></as-directive-name> </div>
is there possibility assign flag roleeditable , check flag in directive-html this:
<div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title"> <div class="badge pull-right" tooltip="role" tooltip-append-to-body="true" if(roleeditable == true) {editable-text="vm.mytext"}>{{vm.mytext}}</div>
thanks lot help! best!
[edit] here code of directive:
(function() { 'use strict'; angular .module('myproject.institution') .directive('asinstitutionpanel', asinstitutionpanel); function asinstitutionpanel() { var directive = { restrict: 'e', replace: true, scope: { asinstitutionuserconnection: '=' }, controller: institutionpanelcontroller, controlleras: 'vm', bindtocontroller: true, templateurl: 'app/... .directive.html' }; return directive; } institutionpanelcontroller.$inject = ['$scope']; function institutionpanelcontroller($scope) { $scope.vm = this; // assumes controlleras: vm var vm = this; vm.institutionuserconnection = this.asinstitutionuserconnection; } })();
is looking for?
html
<div ng-app="app"> <directive flag="true"></directive> </div>
js
var app = angular.module('app', []); app.directive('directive', directive) directive.$inject = []; function directive() { return { restrict: 'e', scope: { flag: '=' }, template: '<fieldset ng-disabled="flag"><input type="text"></fieldset>', controlleras: 'moduloctrl', link:function(scope){ console.log(scope); } }; }
if change flag can enable , disable input inside.
here codepen http://codepen.io/arielcessario/pen/rpdnvl?editors=101
i hope helps.
regards!!
[edit]
if want remove attribute, can add directive:
link:function(scope, element, attributes) {element[0].childnodes[0].childnodes[1].childnodes[1].childnodes[1].removeattribute('editable-text') ; }
if change structure , want know how many childnodes append , index you'd use (i don't know if best way, works me), can , in list of childnodes:
console.log(element);
you should able see whole directive structure , of attributes, if need reason, can change value of node using:
element[0].childnodes[n]...childnodes[n].attributes['node-name'].nodevalue = value;
regards!
Comments
Post a Comment