如何在角度6中的动态创建的元素上绑定事件?

时间:2018-09-18 04:43:10

标签: angular5 angular6

假设我有一些动态创建的元素,其中的类为remove,并且我想附加一个click事件。为了实现这一点,我有无法正常工作的js代码。 IKf,请提供解决方案。

test.compomnent.html

void *count_sum(void *myID){
        int i;
        double local_sum = 0.0, x = 0.0;
        double st = 1.0/((double)NUM_ITER);
        int start = ((int)myID) * (NUM_ITER / NUM_THREAD);
        int end = start + (NUM_ITER / NUM_THREAD);

        printf("myID = %d startPos = %d endPos = %d \n", (int) myID, start, end);

        for(i = start; i < end; i++)
        {
                x = (i + 0.25) * st;
                local_sum += 4.0/(x*x + 1);
        }

        pthread_mutex_lock (&mutexsum);
        global_sum += local_sum;
        pthread_mutex_unlock (&mutexsum);
        pthread_exit(NULL);
}

int main(int argc, char **argv){
    struct timeval t1, t2;
    double elapsedTime;
    int numSlots, myVersion = 1;

    NUM_THREAD = atoi(argv[1]);
    NUM_ITER = atoi(argv[2]);

    // pthread stuff
    int i, rc;
    pthread_t threads[NUM_THREAD];
    pthread_attr_t attr;
    void *status;

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

    gettimeofday(&t1, NULL);

    pthread_mutex_init(&mutexsum, NULL);

    for (i = 0; i < NUM_THREAD; i++ ) {
          rc = pthread_create(&threads[i], &attr, count_sum, (void *)i);
          if (rc) {
            printf("ERROR; return code from pthread_create() is %d\n", rc);
        exit(-1);
          }
    }

    pthread_attr_destroy(&attr);
    for(i=0; i<NUM_THREAD; i++) {
         rc = pthread_join(threads[i], &status);
         if (rc) {
           printf("ERROR; return code from pthread_join() is %d\n", rc);
           exit(-1);
         }
    }

    gettimeofday(&t2, NULL);

    processMem_t myMem; 
    GetProcessMemory(&myMem);
    elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; //sec to ms
    elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
    printf("Memory usage, %u, %u, PTHREAD, DATA, %d, %s, %f, Num_Thread, %d, Num_Iter, %d, SUM, %f\n", myMem.virtualMem, myMem.physicalMem, myVersion, getenv("SLURM_NTASKS"),  elapsedTime, NUM_THREAD, NUM_ITER, global_sum);
    return 0;
}

0 个答案:

没有答案