angularjs-directive

How can i get rid of $parent in angular

老子叫甜甜 提交于 2019-12-20 03:52:29
问题 Here's Plunker I have an external template within in a controller with ng-include. It is shown and hidden based on click event of Button.It is working as required but with $parent in ng-include Template.Is there any other better way of doing this ? Html <body ng-controller="MainCtrl"> <div data-ng-include="'terms.html'" data-ng-show="otherContent"></div> <div ng-show="mainPage"> <p>Hello {{name}}!</p> <button data-ng-click="mainPage=false; otherContent=true">Link to some Content</button> <

Replace text with stars (*) in html with directives in angularjs

爱⌒轻易说出口 提交于 2019-12-20 03:52:25
问题 I need a textarea control with mask able property, if the textarea is mask able then the text should appear as stars instead of actual text. I can have any no of textareas in my form, So i can't save actual text in other variable and save the stars or dots for actual textarea. Can somebody help me to solve this issue? 回答1: As others have already pointed out, it's not possible and should not be done . But here is something which you should give a try. If you really want to achieve it, you'll

Angular JS ng-message inside directive

依然范特西╮ 提交于 2019-12-20 03:19:09
问题 I have some input fields inside custom directive. I'm trying to use ng-message to display validation error text for the fields inside custom directive. When I do submit, validation messages inside custom directive is not shown. My question is, can I use ng-message inside directive, and trigger it using parent action from form controller, and the message is shown? My app.js source sample var app = angular.module('plunker', ['ngMessages']); app.controller('MainCtrl', function($scope) { var vm =

Loading an external script using <script src=“…”> in Angular

风格不统一 提交于 2019-12-20 02:59:21
问题 I need to include a script that has a session ID in the URL (I wouldn't normally do this, but I'm using Crocodoc to embed documents into the page and they don't seem to have another way of doing it without using an iFrame which isn't customizable): <!--sets a global variable "_doc" that is needed for initialization--> <script src="//crocodoc.com/webservice/document.js?session=tohY5vh3dPjUbmW6_imSQFshvQUsJ3fuJFyG7CxBU-E3AArTbELI3U0bSJBm6z5ZKtXpJQCnJ-EU1J2WGbuu6WH4e3Bglcy38TplHg"></script> I

ng-transclude as: element vs attribute

倾然丶 夕夏残阳落幕 提交于 2019-12-20 02:26:46
问题 I want to create a wrapper directive that would serve as the frame for a notification widget in a list. In that frame I want to transclude later some specific content based on a property from the notif object. Currently I hard coded a div element. I have the following in index.cshtml: <div ng-controller="notificationCenterCtrl"> <ul> <li ng-repeat="notif in allNotifications"> <notification-base notification="notif" remove="removeNotification(notif)"> <div style="background-color: fuchsia">bla

Template always compiles with old scope value in directive

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 01:19:35
问题 I've got a directive that's working like this: http://jsfiddle.net/smithkl42/cwrgLd0L/23/ App.directive('prettify', ['$compile', function ($compile) { var templateFn; return { restrict: 'E', scope: { target: '=' }, link: function (scope, element, attrs) { if (!templateFn) { var template = element.html(); templateFn = $compile(template); } scope.$watch('target', function (newVal, oldVal) { var compiled = templateFn(scope); element.html(''); element.append(compiled); var html = element.html();

Template always compiles with old scope value in directive

独自空忆成欢 提交于 2019-12-20 01:19:07
问题 I've got a directive that's working like this: http://jsfiddle.net/smithkl42/cwrgLd0L/23/ App.directive('prettify', ['$compile', function ($compile) { var templateFn; return { restrict: 'E', scope: { target: '=' }, link: function (scope, element, attrs) { if (!templateFn) { var template = element.html(); templateFn = $compile(template); } scope.$watch('target', function (newVal, oldVal) { var compiled = templateFn(scope); element.html(''); element.append(compiled); var html = element.html();

Validation messages are not getting displayed when trancluding a directive within another directive

霸气de小男生 提交于 2019-12-20 01:10:07
问题 To reduce the boilerplate code for html validations i am writing two directives: one for templating and another for validations... both directives do work as expected and angularjs validation classes do get attached to the invalid input tags, only problem i am facing the validation messages which are part of templating directive are not getting displayed. PLUNKER LINK The problem seems to be with the way child element is compiled: element.replaceWith($compile(template)(scope)); this should

Angular JS Directive - Template, compile or link?

大憨熊 提交于 2019-12-19 22:07:15
问题 I would like to create an Angular JS directive to check the length of a string, if it is too long to shorten it using a Filter, and show an Angular-UI popover on mouseover. Where in the directive should I be placing the functionality to get this to work (link, template or compile)? The view: <div myapp-shorten="project">{{project.Description}}</div> Here are my first attempts at the directive so far: angular.module('myapp.directives', []) .directive('myappShorten', function () { function link

How to stop ng-click from a custom directive in AngularJS?

痞子三分冷 提交于 2019-12-19 20:35:42
问题 LIVE DEMO Consider the following myButton directive: angular.module("Demo", []).directive("myButton", function() { return { restrict : "E", replace: true, scope: { disabled: "=" }, transclude: true, template: "<div class='my-button' ng-class='{ \"my-button-disabled\": disabled }' ng-transclude></div>", }; }); which can be used like this: <my-button disabled="buttonIsDisabled" ng-click="showSomething = !showSomething"> Toggle Something </my-button> How could I stop ng-click from executing when