ng-repeat中的angularjs将ng-init和受理人数据调用到动态创建的类中

时间:2016-06-09 07:00:54

标签: angularjs

我有一个ng-repeat div。在那,我想使用ng-init指令调用一个函数;在该函数中,我想通过创建的动态id动态地将数据附加到div。但是,我没有在get_All_ImagesData函数中获得动态创建的ID。

我希望能够在ng-Repeat循环中调用此函数。

代码低于

import java.io.File;
import java.util.Scanner;

public class parseTxt {

    private static Scanner fileReader ;

    public static void main(String[] args)
    {
        try{
            readData("33");
        } catch(Exception e){
            System.out.println("Exception : " + e);
        }   
    }  

    private static void readData(String id) throws Exception{
        fileReader = new Scanner(new File("E://data.txt"));
        String cusId, fname, lname, dollar;

        while(fileReader.hasNextLine()){
            String line = fileReader.nextLine();
            String[] lineParts = line.split(" ");

            if(lineParts[0].equals(id)){        // lineParts[0] is ID NUMBER
                cusId = lineParts[0];
                fname = lineParts[1];
                lname = lineParts[2];
                dollar = lineParts[3];

                System.out.println("Customer ID : #" + cusId);
                System.out.println("First Name : " + fname);
                System.out.println("Last Name : " + lname);
                System.out.println("Dollar Amount : $" + dollar);

                break;
            } else {
                System.out.println("This ID:" + id + " does not exist");
            }
        }

    }
}

控制器中的功能:

try (SeekableByteChannel ch = Files.newByteChannel(Paths.get("test.txt"))) {
    ByteBuffer bb = ByteBuffer.allocateDirect(1000);
    for(;;) {
        StringBuilder line = new StringBuilder();
        int n = ch.read(bb);
        // add chars to line
        // ... don't forget to break
    }
}

1 个答案:

答案 0 :(得分:0)

" Angular方式"是让模型驱动DOM。您不应该像在函数中那样从控制器手动操作DOM。在模板中写下所有HTML,然后更改模型以更改视图。

<div class="active-task-body" data-ng-repeat="items in UserAssignTaskAllData">
  <div class="col-md-12">
    <a href='' ng-if="items.TaskDetailAttachment">
      <img 
        ng-src="{{current_page_url}}Content/images/filetype/image.jpg" 
        height="30" 
        width="30" />
    </a>
  </div>
</div>

请注意,current_page_url应该是$scope的属性才能实现此目的。