标签: lumx

使用"controller as ..."语法时,在另一个指令中的第三方指令

这是重新创建我的问题的代码片段:

HTML:

...
<div ng-controller="worker as workerCtrl">
    <my-directive label="label" controllerAs="workerCtrl" function="fileUpload(e, this.options)"></my-directive> 
</div>
Run Code Online (Sandbox Code Playgroud)

控制器:

...
function fileUpload(file, options){...}
...
Run Code Online (Sandbox Code Playgroud)

指示:

function myDirective($compile) {

    var directive = {
        restrict: 'E',
        link: link
    };
    return directive;

    function link(scope, element, attrs) {
        var htmlText = '<lx-file-input ' +
            'change="'+attrs.controllerAs+'.'+attrs.uploadFunction+'" ' +
            'label="'+attrs.label+'"></lx-file-input>';
        element.replaceWith($compile(htmlText)(scope));
    }
}
Run Code Online (Sandbox Code Playgroud)

应该是:('lx-file-input'是第三方指令......)

<lx-file-input change="workerCtrl.fileUpload(e, this.options)" label="someLabel"</lx-file-input>
Run Code Online (Sandbox Code Playgroud)

问题是Angular编译和链接的时间关闭,模板留下HTML字符串而不是编译的函数.我知道如果我将控制器设置在指令中但它希望它在HTML中的相同"workerCtrl"范围内使用相同的函数,它将起作用.

javascript angularjs angularjs-directive lumx

5
推荐指数
1
解决办法
189
查看次数

LxNotificationService服务在AngularJS app中不起作用

我最近开始使用AngularJS和Lumx.我已尝试添加可在网站"通知"标签下找到的通知.链接在这里.

无论如何,我得到的错误是

"错误:未定义LxNotificationService"

所以我将它添加到控制器中的服务列表中.

下面是我的app.js文件

var testing = angular.module('testing', []);
Run Code Online (Sandbox Code Playgroud)

testing.controller('mainCtrl',function($ scope){

$scope.notify = function(type)
{
    if (type === 'simple')
    {
        LxNotificationService.notify('Lorem Ipsum');
    }
    else if (type === 'sticky')
    {
        LxNotificationService.notify('Lorem Ipsum', undefined, true);
    }
    else if (type === 'icon')
    {
        LxNotificationService.notify('Lorem Ipsum', 'android');
    }
    else if (type === 'color')
    {
        LxNotificationService.notify('Lorem Ipsum', undefined, false, 'grey');
    }
    else if (type === 'info')
    {
        LxNotificationService.info('Lorem Ipsum');
    }
    else if (type === 'success')
    {
        LxNotificationService.success('Lorem Ipsum');
    }
    else if (type …
Run Code Online (Sandbox Code Playgroud)

angularjs lumx

2
推荐指数
1
解决办法
572
查看次数

标签 统计

angularjs ×2

lumx ×2

angularjs-directive ×1

javascript ×1