如何使用 angularjs 在 html 中插入 QlikSense Element

How to insert QlikSense Element in html using angularjs

我尝试使用 angularjs 将在 Qlik Sense 中创建的一些元素插入到混搭应用程序中。我有一项服务可以从 Qlik Sense 获取对象。 Sense 给我一个承诺。但是这些承诺我不知道如何插入 html 代码。

这是我的代码

define([
'js/qlik',
'app'
], function(qlik, app) {

let prefix = window.location.pathname.substr(0, window.location.pathname.toLowerCase().lastIndexOf("/extensions") + 1);
let config = {
    host: window.location.hostname,
    prefix: prefix,
    port: window.location.port,
    isSecure: window.location.protocol === "https:"
};

app.service('cube', function() {
    const appSense = qlik.openApp('data.qvf', config);


    this.getElement = function(id) {
        return appSense.getObject('filter-div', 'ABFqkb');
    };
}
});

这是我的控制器:

define([
'app',
], function(app) {
app.controller('controller', function($scope, cube) {

    cube.getElement().then(function(data) {
        console.log(data);
    });
    // create a message to display in our view
});
});

我的看法是这样的

<div ng-controller="datos-generales">
    <div id='filtro-datos'></div>
</div>

谁能帮我插入那个元素?

使用 $q.when 将 ES6 promise 转换为 AngularJS promise:

app.controller('controller', function($scope, $q, cube) {

    var promise=$q.when(cube.getElement())

    promise.then(function(data) {
        $scope.data = data; 
        console.log(data);
    });

});

HTML

<div ng-controller="datos-generales">
    <div id='filtro-datos'>
        {{data}}
    </div>
</div>

$q.when 将可能是值或(第 3 方)then-able 承诺的对象包装到 $q 承诺中。当您处理可能是也可能不是承诺的对象,或者如果承诺来自不可信的来源时,这很有用。

AngularJS 通过提供自己的事件处理循环来修改正常的 JavaScript 流程。这将 JavaScript 分为经典和 AngularJS 执行上下文。只有在 AngularJS 执行上下文中应用的操作才能受益于 AngularJS 数据绑定、异常处理、属性 监视等


更新

或者,转换服务中的 ES6 promise:

app.service('cube', function($q) {
    const appSense = qlik.openApp('data.qvf', config);    
    this.getElement = function(id) {
        var es6promise = appSense.getObject('filter-div', 'ABFqkb');
        return $q.when(es6promise);
    };
}
app.controller('controller', function($scope, ̶$̶q̶,̶ cube) {

    cube.getElement()
      .then(function(data) {
        $scope.data = data; 
        console.log(data);
    });

});

这样控制器就不需要进行转换了。