简体   繁体   English

Angular.js + PHP:如果在ngSanitized html模板中,则不执行角度表达式

[英]Angular.js + PHP: angular expression not executed if inside a ngSanitized html template

i'm trying to accomplish something really nice (and really strange). 我正在尝试完成一些非常好(也很奇怪)的事情。

I've got an angular controller calling (with $http.get, passing arguments got from angular) a php script which gets some data from the database and decide to echo one out of two possible html templates. 我有一个角度控制器调用(使用$ http.get,传递从angular获取的参数)一个php脚本,该脚本从数据库中获取一些数据并决定回显两个可能的html模板中的一个。

The problem is, in those templates there are expressions which should be parsed by angular. 问题是,在那些模板中,存在应按角度解析的表达式。 They don't. 他们没有。

Here are the scripts: 以下是脚本:

the first angular controller: 第一个角度控制器:

    $http.get("../php/jwtCheck.php?token=" + localStorage.token + "&courseid=" + $stateParams.id).success(function (response) { 

       $scope.phpData = $sce.trustAsHtml(response);

    });

the receiving php script: 接收PHP脚本:

//doing mysql stuff
if (sqlStuff::isBought($row[bought], $stuffID)){
                include '../boughtTemplate.html';
            } else
            {
                include "../previewTemplate.html";
            }

inside the templates i have this call to angular $scope: 在模板内,我有这个对angular $ scope的调用:

<video data-html5-video="{{generateVideoFolder($index)}}" data-controls="true" data-preload="false" data-width="400" data-height="224">
</video>

which never got parsed by angular. 从来没有被角度解析。

Any idea? 任何想法?

You need to compile phpData . 您需要编译phpData

Here is one approach I stole from another SO question: https://stackoverflow.com/a/29994559/3563439 这是我从另一个SO问题中窃取的一种方法: https : //stackoverflow.com/a/29994559/3563439

See the solution applied to your case in my Fiddle: http://jsfiddle.net/masa671/zfftw7qr/ 在我的小提琴中查看适用于您的案例的解决方案: http : //jsfiddle.net/masa671/zfftw7qr/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM