`ng-repeat` - directive for `$scope` array length with keeping `html` template

in my app, i have the html template nested in page. I require to use the same template for other array of elements.

and the directive should works as usual. In my case link method is not called.

Please any one guide me for correct approach to get this out.

here is my html :

<div class="content" ng-controller="main"> <span class="dgt" ng-repeat="digitDispaly in digitalArray"> //repating <span class="sr"> <span>0</span> <span>1</span> <span>2</span> <span>3</span> <span>4</span> <span>5</span> <span>6</span> <span>7</span> <span>8</span> <span>9</span> </span> <span class="fl"></span> </span> <span class="line">Line</span> </div>

js :

angular.module('myApp', []) .controller("main", function($scope) { $scope.digitalArray = ["3", "2", "7"]; }); angular.module("myApp") .directive("digitDispaly", function () { return { restrict : "E", link : function (scope, element, attrs) { console.log("hi") } } })

Live Demo

-------------Problems Reply------------

You Can also use it as class as shown below

http://plnkr.co/edit/eCCVW8obKdCNvKKGmd9S?p=preview

<span class="dgt digitDispaly " ng-repeat="digitDispaly in digitalArray"> //repating

angular.module("myApp")
.directive("digitDispaly", function () {
return {
restrict : "C",
link : function (scope, element, attrs) {
console.log("hi")
}
}

})

It's because you have used

restrict : "E",

Which means that your directive is applied only on element tags. Like this:

<digit-dispaly></digit-dispaly>

Your updated plunkr: http://plnkr.co/edit/Kaq2MtYcVTLZsNalNbAm?p=preview

I'd suggest reading a bit about directives: https://docs.angularjs.org/guide/directive

Category:javascript Views:3 Time:2018-12-29

Related post

  • SIMD array add for arbitrary array lengths 2012-04-16

    I'm learning to use SIMD capabilities by re-writing my personal image processing library using vector intrinsics. One basic function is a simple "array +=," i.e. void arrayAdd(unsigned char* A, unsigned char* B, size_t n) { for(size_t i=0; i < n;

  • Mobile Web Form - Can radio buttons be custom styled for Android and iPhone with CSS & HTML? 2011-05-02

    My question is fairly straight-forward, however, side note: I also would like to make sure that any customizations degrade easily for other phones. Can radio buttons be custom styled for Android and iPhone with CSS & HTML? Thanks, s -------------

  • how to set array length with delphi 2010 rtti 2009-11-20

    how to set array length in runtime ? setLength(t.GetProperty('Propertys'),3); ???? unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TSubProperty = Class private Fitem2: Inte

  • What is the best embedded system board/chip combination for video pass through with a HTML overlay 2010-02-02

    I am trying to build a proof of concept for a consumer electronic product that will have a video input & output, but will output with an HTML overlay on part of the screen. Does anyone know of the best board/chip combination that would be good fo

  • Warning: This page calls for XML namespace declared with prefix [HTML element name] but no taglibrary exists for that namespace 2011-12-26

    I have a problem with one JSF page. This is the source code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns:h="http://java.sun.com/jsf/html"> <head> <titl

  • Getting HTML array length with Javascript 2011-08-29

    I am dynamically creating inputs when the users double clicks an element in a select box. There can be multiple inputs per element type, so I am creating them as HTML arrays. When the inputs are created, a link is also created that points to a javasc

  • for loop array length 2011-04-05

    var stack = new Array(); var ii = 0; function pushTutor(item) { var jj = stack.length; for(ii=0;ii<jj;ii++) { stack.push(item); alert(stack); } } I remember the stack.length cause the issue which is not able to loop at all. What is the solution fo

  • array length with key-value, js 2011-12-16

    I wrote this piece of code, that should parse the given paramUnparsed (which should be an array in the form: [key1=val1, key2=val2, .., keyn=valn]). function parseParams(paramUnparsed){ var params = []; for ( var j = 0; j < paramUnparsed.length; j

  • Register directive for controls in App_Code with no namespace 2009-07-02

    I know that if I created a custom control, say MyLabel in App_Code .. namespace MyNamespace { public class MyLabel : Label { .. } } To access this control in my page, I would use this directive .. <%@ Register tagPrefix="foo" Namespace="MyNamespac

  • smarty relative links with in html templates? 2012-01-20

    how do we include style sheets from a template file in smarty? ca we use a relative path or does it have to be n absolute path? structure might look like project |-- library |-- css |-- style.css |--template |--index.tpl |--template_c in the index.tp

  • jquery/javascript - howto compare arrays, retrieve array(s) with highest number of elements? 2011-10-21

    I'm sitting over the following array-problem: I have four arrays 1,2,3,4 each can contain any number of elements I'm looking for the array(s) with the highest number of elements (and its 2nd to last element) I'm using this: var arr = [], $panels = $(

  • Do loops check the array.length every time when comparing i against array.length? 2011-12-09

    I was browsing around and I found this: var i, len; for(i = 0, len = array.length; i < len; i++) { //... } My first thoughts are: Why he did that? (it must be better for some reason) Is it worth it? (I assume yes, why else he will do it this way?)

  • Direct array initialization with a constant value 2009-03-15

    Whenever you allocate a new array in C# with new T[length] the array entries are set to the default of T. That is null for the case that T is a reference type or the result of the default constructor of T, if T is a value type. In my case i want to i

  • What is inside code for array.length() in Java? 2011-02-05

    What is stored in 10th location of array say int[] array=new int[10]; Say we have values stored from array[0] to array[9], if I were to print elements without using array.length() or for (int a: array) How do I proceed? My basic question is how will

  • How to repeat the array elements with specific sequence according to some number? 2012-02-20

    If I have this array of integers : int[] columns_index = { 2, 3, 4}; How can i repeat this sequence according to given number (size)? For example : if i give u 4 as a size then the array will be {2,3,4,2} if i give u 5 as a size then the array will b

  • Angular directive for finish ng-repeat when splice() elements 2014-02-20

    I've created a directive for Angular to know when a ng-repeat is finished. I've found the most common solution is something like is used here - Calling a function when ng-repeat has finished But, Why the directive is just triggered when an element is

  • What is the data type for length property for Java arrays? 2008-10-17

    I want to find out if length property for Java arrays is an int/long or something else. --------------Solutions------------- It is an int. See the Java Language Specification, section 10.7. In Java Language spec, Arrays you can see in 10.4: Arrays mu

  • Can one initialise a java String with a single repeated character to a specific length 2009-12-14

    I'd like to create a function that has the following signature: public String createString(int length, char ch) It should return a string of repeating characters of the specified length. For example if length is 5 and ch is 'p' the return value shoul

  • malloc 2D array for CG Rects, initializing with array notation 2011-04-15

    int rows = 2; int columns = 2; positions = malloc(rows * sizeof(CGRect)); for(int i=0; i<rows; i++){ positions[i] = malloc(columns * sizeof(CGRect)); } positions[0][0] = CGRectMake(0, 0, 1, 1); positions[0][1] = CGRectMake(1, 1, 2, 2); positions[0

  • Print array length for each element of an array 2011-07-12

    Given a string array of variable length, print the lengths of each element in the array. For example, given: string[] ex = {"abc", "adf", "df", "ergd", "adfdfd"); The output should be: 2 3 4 6 One possibility I'm considering is to use a linked list t

  • for( - in -) not working with array 2011-08-25

    I'm somehow confused: I have a list of commands like this: var commands = [{"command": "read"}, {"command": "write"}, {"command": "login"}]; If I try it access one of the commands like this it works: console.log(commands[0]["command"]); // Output is

  • Crashes with [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array error 2011-10-22

    I am getting crash reports via users of my iOS app, but crash I can't reproduce myself, nor can I trace the error back to a line in my own code (except that it originates from line 14 in main.m but this is the default application creation of iOS apps

  • Different results for comparing Array[][] with SequenceEqual() and custom method 2011-10-28

    can someone explain me why I do get different results? bool result = true; for (int row = 0; row < State.Rows; row++) { for (int col = 0; col < State.Cols; col++) { if (map[row][col] != other.map[row][col]) //if (!map[row][col].Equals(other.map

  • subsonic - Offset and length were out of bounds for the array intermittent error 2011-12-20

    inherited a website which uses subsonic 2.0 and gets an intermittent error of "Offset and length were out of bounds for the array" . If we were to restart the app or recycle the app pool, the issue would go away. I suspect it has something to do with

  • Java: Setting array length for an unknown number of entries 2009-12-02

    I am trying to fill a RealVector (from Apache Commons Math) with values. I tried using the class's append method, but that didn't actually add anything. So now I'm using a double[], which works fine, except I don't know in advance how big the array n

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.077 (s). 11 q(s)