sce trust as html不打印HTML

时间:2015-06-16 10:47:25

标签: javascript angularjs

所以我有以下HTML:

<p>Mmmhmmmmmm</p>

非常简单(但它确实比这更先进,但暂时让我们使用上面的例子)

此值存储在$scope值中:$scope.selected.textContent

因此,为了打印它,我使用了以下内容:

    <div class="row">
    <div class="col-xs-12">
        {{$sce.trustAsHtml(selected.textContent)}}
    </div>
</div>

然而它什么都不打印。

如果我执行以下操作:

{{$sce.trustAsHtml(selected.textContent) || 'Hello'}}

打印出Hello

谁能告诉我我做错了什么?

1 个答案:

答案 0 :(得分:2)

使用ng-bind-html代替

    int key;
    int messCount=0;
    int count=0;
    ConnCrypto m = new ConnCrypto();
    String[] s = {};
    GameCrypto g = new GameCrypto(s);
    int i = g.init();
    Socket tcp;
    BufferedReader reader;
    BufferedWriter writer;
    CryptHandler crypt= new CryptHandler();
    static int err=0;

    void setup() throws IOException {
        tcp = new Socket(serverIp, serverPort);
        InputStream InputStream = tcp.getInputStream();
        OutputStream OutputStream = tcp.getOutputStream();
        InputStreamReader InputStreamReader = new InputStreamReader(InputStream);
        OutputStreamWriter OutputStreamWriter = new OutputStreamWriter(OutputStream);
        reader = new BufferedReader(InputStreamReader);
        writer = new BufferedWriter(OutputStreamWriter);
    }

    void send(String z) throws IOException {
        System.out.println("Send:\t" + z);
        z = m.encrypt(z);
        writer.write(z);
        writer.newLine();
        writer.flush();
    }

    void crypt(String z) throws IOException {
        System.out.println("Send:\t" + z);
        z = crypt.crypt(z);
        z = "d " + messCount + " "+(char)1 + z;
        send(z);
        messCount++;
    }

    void crypt2(String z) throws IOException {
        z = g.encrypt(z);
        z = "d " + messCount + " " + z;
        send(z);
        messCount++;
    }

    String recv() throws IOException {
        char chr;
        StringBuilder sb= new StringBuilder();
        while((chr=(char)reader.read())!=0x0A)
            sb.append(chr);
        String str=sb.toString();
        if (key != 0) {
            str = m.decrypt(str);
            int gg = str.charAt(0);
            if (gg == 100) {
                System.out.print("Raw:\t"+str);
                str = "d " + crypt.decrypt(str.substring(5));
            }
        } 
        else if (str.charAt(0) == 99) {
            key = Integer.parseInt(str.substring(5));
            m.init(i, key);
        }
        System.out.println("Recv:\t" + str);
        return str;
    }

并在您的控制器中

<div class="col-xs-12" ng-bind-html="htmlHere">
</div>