angularjs-directive

AngularJs, change menu item whether user is connected or not

坚强是说给别人听的谎言 提交于 2019-12-06 08:35:29
问题 I am new to AngularJS and I try to deal with user authentication. I ensure non connected user can't access restricted route : app.js .config(function ($routeProvider) { $routeProvider .when('/myroute', { templateUrl: 'views/myroute.html', controller: 'MyrouteCtrl', access: { isFreeAccess: false } }) ... .run( function ($rootScope, $location, Auth) { $rootScope.$on('$routeChangeStart', function(currRoute, prevRoute){ if (prevRoute.access != undefined) { // if route requires auth and user is

Double indirection in data-binding. Interpolate string in a template

我的梦境 提交于 2019-12-06 08:33:40
问题 I'm trying to resolve double binding in the link function of a directive: scope.a = "surprise"; scope.b = "{{ a }}"; the template is <div>{{ b }}</div> it's rendered like <div>{{ a }}</div> is it possible to get the view to display <div>surprise</div> ? I've been trying to recompile the directive, but once b is binded, contents are a string and angularJS won't attempt any more to bind them. 回答1: One way is to interpolate on function rather then value directly function test($scope) { $scope.a

How to get controller scope from multi-level directives in AngularJS(without $parent)

陌路散爱 提交于 2019-12-06 08:33:34
How can I access controller scope from multi-level directives in below structure: I create a directive that has multi-level scopes inside its. 1. Controller scope 1.2. Directive1 scope(main directive) 1.2.1. Directive2 scope 1.2.1.1 Directive3 scope I want to get the controller scope from directive 3. please don't refer to $parent because the parent level it's not certain and a user may use this directive inside another directive.(see below codes) <div ng-controller="Test"> <custom-dir> <dir1> <dir2> <dir3> </dir3> </dir2> </dir1> <custom-dir> </div> The users create a function in the Test

AngularJS multiple directives on same element, $compile:multidir ERROR

♀尐吖头ヾ 提交于 2019-12-06 08:15:39
Here is the plunkr: http://plnkr.co/edit/CzcVzKSvpKJTuTKARVJz?p=preview and this is my simple code: .directive('ngB', [function () { return { 'restrict': 'A', 'scope': { 'ngB': '=' }, 'link': function($scope, el) { var clss = 'b' , go = function () { if ($scope.ngB) { el.removeClass('a'); el.addClass(clss); } else { el.removeClass(clss); } }; $scope.$watch('ngB', function () { go(); }); } }; }]) .directive('ngF', [function () { return { 'restrict': 'A', 'scope': { 'ngF': '=' }, 'link': function($scope, el) { var clss = 'f' , go = function () { if ($scope.ngF) { el.removeClass('a'); el.addClass

AngularJS $setViewValue() Not Responding in $parsers.push()

☆樱花仙子☆ 提交于 2019-12-06 08:09:18
I have a directive. It requires ngModel , and in the link, I should be able to use modelCtrl parameter to use $setViewValue(); and $render(); in conjunction to return to change the value in my input field and update the value stored in ngModel . Unfortunately, when I pass modelCtrl into my logic function, I cannot use $setViewValue(); and $render(); , even though I pass modelCtrl to the function. (See fiddle: http://jsfiddle.net/GSTC5/1/ ) myApp.directive('demo', function() { return { require: 'ngModel', restrict: 'EACM', link: function(scope, element, attrs, modelCtrl) { setAndRender

AngularJS: Alerts don't show up when multiple messages change ngModel for message

淺唱寂寞╮ 提交于 2019-12-06 07:43:19
I have a notification service which works well for when page is loaded and Controller is loaded But when I have different buttons calling different functions, they change message, but alerts don't show up Here is a plunker for that - http://plnkr.co/edit/YioiJXNkaET6T2mexjCq?p=preview What is that I need to do to update it whenever $scope.message changes? You could $watch the model and show the alert when it changes. http://plnkr.co/edit/fJuP9LWH4MNVV1cQs3ED?p=preview In linker function of your directive: link: function(scope, element, attrs) { scope.$watch('ngModel', function() { element.show

angularjs custom directive conditional templateUrl via attribute

孤者浪人 提交于 2019-12-06 07:19:42
I am trying to load conditional template urls via attributes, my directives is as follows. The directive is in a ng-repeate and when box.key == 'experiences' the expression is returning education-form.php and not experiences-form.php. <div multiple-form directive-data='directiveData' template-url="box.key == 'experiences'? 'experiences-form.php':'education-form.php'" item="item" forms="forms" form-name="{{box.key}}{{item._id}}" onsave="updateMultipleUser(box.key, item._id, $data)" onreset="formAction($formName, 'reset')" cancel="formAction($formName, 'cancel')" > </div> Directive DDO {

AngularJS nested directives are inserted outside their supposed parent element

穿精又带淫゛_ 提交于 2019-12-06 06:48:31
I'm having trouble understanding how nested directives work with AngularJS. var app = angular.module('plunker', []); app.directive('myTable', function() { return { restrict: 'E', template: [ '<table class="table table-query" ng-show="queries.length">', '<thead>', '<tr>', '<th class="query-name">Name</th>', '<th class="query-status">Status</th>', '</tr>', '</thead>', '<tbody>', '<my-row ng-repeat="query in queries track by $index"', 'query="query">', '</my-row>', '</tbody>', '</table>', ].join(''), scope: { queries: '=' }, controller: function() { }, link: function(scope, element) { } }; });

AngularJS Directive is not linking when using an input in the template to replace an input in the html with the type attribute specified

蓝咒 提交于 2019-12-06 06:44:01
问题 I'm having a really specific, strange issue. We have to code our app to support IE8. We are wrapping the Angular-Bootstrap's Typeahead directive in a template to encapsulate a lookup widget with some extra functionality. The issue we're having is that our directive template looks like this: '<input ng-model="typeaheadValue" typeahead="xxx.code as formatXxx(xxx) for xxx in searchXxxs($viewValue)">' Inside the link function in the directive we are simply calling replace: true and passing in

Can I require generic parent directive in AngularJS

北城以北 提交于 2019-12-06 06:41:20
问题 Can a child directive require a parent without knowing exactly which directive that parent is, just that it "implements an interface"? For example: <parentImplX> <child></child> </parentImplX> In the above example I want the controller injected into child to be ParentImplXCtrl . But If I do: <parentImplY> <child></child> </parentImplY> I want the controller to be ParentImplYCtrl . directives.directive("parentImplX", function () { return { scope: {}, restrict: "E", controller: ParentImplXCtrl