angularjs-directive

AngularJs Directive Template with ng-transclude cannot be compiled

旧时模样 提交于 2019-12-22 04:41:27
问题 I am trying to create two directives. The first directive appends other predefined angular directives (ng-click and ng-class) to the element and then compiles it so that they work. The second directive replaces an element for a template which contains the first directive. I use ng-transclude to carry the element's contents over to the template. The problem is that once the template from directive 2 is added the first directive tries to compile and throws a wobbly: "TypeError: undefined is not

How do I use ngOptions with a string that contains HTML entities?

这一生的挚爱 提交于 2019-12-22 04:39:41
问题 I'm using ngOptions to built a selection menu but one of my labels has an HTML entity in it & . The label shows up as Books & Stuff not Books & Stuff . My jade is this: select(ng-show="isType === 'select'", id="{{id}}", ng-model="model", ng-options="o.id as o.label for o in options") How can I get HTML entities to display properly? Update I'm trying the answer by sal: select(ng-show="isType === 'select'", id="{{id}}", ng-model="model") option(ng-repeat="o in options", ng-bind-html="o.label",

Angular: How to force recompile directive?

不问归期 提交于 2019-12-22 04:33:32
问题 HTML: <div ng-repeat="obj in arr"> <custom-directive status-stored-in="obj"></custom-directive> </div> Problem: I have page-turn built in for the large amount of obj s. Which means that the value of arr , representing the current page of obj s, will change. However, the obj in the status-stored-in="obj" part is not refreshed with the change. Right now my solution is to add a ng-if in customDirective , flickering its value back and forth to have it force recompiled. Is there any other

How do you check if & variable is set in directive

坚强是说给别人听的谎言 提交于 2019-12-22 04:15:12
问题 In a directive, where you set a method callback through an arg, say: <my-directive callback='showAlert()' /> You can retrieve the variable through the scope setting in the return: scope: { callback: "&callback" } If the callback is not set, eg: <my-directive /> The value of $scope.callback is still: $scope.callback():function (locals) { return parentGet(scope, locals); } Is there a good way to check that the callback was not set? 回答1: One way i can think off is to check the attribute

Angularjs - ng-click function vs directive

廉价感情. 提交于 2019-12-22 03:41:25
问题 I can't decide which method to use in following case. I'm trying to alert when clicking on buttons. I can do this using 2 methods. Which is the best practice and please tell me why? Method 1 <div ng-app="app"> <button alert>directive</button> </div> var app = angular.module('app', ['ngRoute']); app .directive('alert', function(){ return { link: function(scope, element, attr) { element.on('click', function(){ alert('clicked'); }) } } }) Method 2 <div ng-app="app" ng-controller="MainCtrl">

Angularjs directives isolated scope + one-way data-binding not working for objects?

时光怂恿深爱的人放手 提交于 2019-12-22 03:32:10
问题 I have created a custom directive which has two values. first is config object and second is data object. I modify this config and data objects inside my directive which is reflecting it in parent scope. Which is causing me error when I have to use directive multiple times. I followed https://umur.io/angularjs-directives-using-isolated-scope-with-attributes/ and I am using isolated scope. I want one way data binding for objects in isolated scope. Whatever I change in directive function it

Angularjs directives isolated scope + one-way data-binding not working for objects?

早过忘川 提交于 2019-12-22 03:31:12
问题 I have created a custom directive which has two values. first is config object and second is data object. I modify this config and data objects inside my directive which is reflecting it in parent scope. Which is causing me error when I have to use directive multiple times. I followed https://umur.io/angularjs-directives-using-isolated-scope-with-attributes/ and I am using isolated scope. I want one way data binding for objects in isolated scope. Whatever I change in directive function it

$locationChangeSuccess triggers four times

白昼怎懂夜的黑 提交于 2019-12-22 01:36:09
问题 I am new to angular Js. My application flow is as below: 1) I have a view controller wherein, each view controller sets the breadcrumb data with the help of Breadcrumbs factory. 2) Breadcrumbs factory takes data from view controller and attaches data to $location.$$state object.(reason for storing in state object is if back button is pressed, view controller doesn't instantiate so I can refer history data for breadcrumbs ) below is code to attach data to state object: var state = $location

ng-repeat not binding when directive template is loaded via templateUrl

时间秒杀一切 提交于 2019-12-22 00:15:52
问题 I've been stuck on this for hours and hours - can anyone help? I have a list of nested directives, which I'm iterating through ng-repeat. The templates for these directives are fairly chunky so I've modularised them into separate HTML files and loaded them via templateUrl, but this seems to be breaking the data binding. I've replicated the problem here: http://plnkr.co/edit/72HUb0vhtpYWuRHnlq3b?p=preview HTML: <div project-ext ng-repeat="project in projects"></div> project.html {{project.name

ng-pluralize with translations Error:“TypeError”

断了今生、忘了曾经 提交于 2019-12-21 23:27:59
问题 Hi I am trying to localize the strings for pluralization in Angular. I am using ng-pluralize directive to handle pluralization and for localizations I am passing the strings to the directive at runtime based on user locale. But I am getting error "TypeError: Object # has no method 'one'" even if the $scope is loaded with translated strings.Following is my html code, <input class="input-text" type="number" ng-model="candyCount" ng-keypress="loadStrings()"/> <ng-pluralize count = "candyCount"