AngularJS指令动态模板ng-repate不起作用

时间:2016-10-06 15:57:19

标签: angularjs

当我想在html模板中显示循环索引+ 1时,我遇到了问题。

这是JS代码:

#include <stdio.h>
#include <stdlib.h>

#define MAX_SIZE 50000

void merge (int arr[], int start, int mid, int end){
    /* two sorted arrays arr[start ... mid]
       and arr[mid+1 ... end] merge them */
    int tempvals[MAX_SIZE];
    int ptr1, ptr2, ptrnew=0, idx;

    ptr1 = start;
    ptr2 = mid+1;

    /* compare both the sorted arrays element by element
       move the element that is smaller to the new aray */
    while ( (ptr1 <= mid) && (ptr2 <= end)){
        /* compare elements at ptr1 and ptr2 */
        if (arr[ptr1] < arr[ptr2]){
            tempvals[ptrnew] = arr[ptr1];
            ptr1 ++; ptrnew++;
        } else {
            tempvals[ptrnew] = arr[ptr2];
            ptr2 ++; ptrnew++;
        }
    }
    /* at this point --> one of the pointers has reached the end */
    while (ptr1 <= mid){
        tempvals[ptrnew] = arr[ptr1];
        ptr1 ++; ptrnew++;
    } 
    while (ptr2 <= end){
        tempvals[ptrnew] = arr[ptr2];
        ptr2 ++; ptrnew++;
    }

    /* transfer back to arr */
    for (idx = start, ptrnew = 0; idx <= end; idx++, ptrnew++)
        arr[idx] = tempvals[ptrnew];
}

void merge_sort (int arr[], int start, int end){
    int mid = (start + end)/2;
    /* termination condition */
    if( start >= end) return;

    /* recurse */
    merge_sort(arr,start, mid); /* first half */
    merge_sort (arr, mid+1, end); /* second half */
    merge (arr, start, mid, end); /* do the merging */
}
void print_array (int arr[], int size){
    int i;
    for (i=0; i < size; i++)
        printf ("%d ",arr[i]);
    printf ("\n");
}
int main(){
    int arr[MAX_SIZE]; 
    int i;
    /* initialize */
    for (i=0; i < MAX_SIZE; i++)
        arr[i] = rand(); 

    /* sort and print */
    merge_sort (arr,0, MAX_SIZE - 1);
}

1 个答案:

答案 0 :(得分:0)

您应该传递指令的参数,而不是像这样调用控制器方法:

<list-numbers numbers="[1,2,3,4,5]"></list-numbers>

或者可能是这样:

<list-numbers numbers="getNumber(myOtherNumber)"></list-numbers>


app.directive('listNumber', function() {
    return {
        restrict: 'E',
        scope: {
            numbers: '='
        },
       template: '<ul><li ng-repeat="i in numbers track by $index"><span>{{$index+1}}</span></li></ul>'
    }
});