角度错误我不明白? [英] Angular error i dont understand?

查看:33
本文介绍了角度错误我不明白?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建此处的菜单:

I am trying to build the Menu that is here:

http://jsfiddle.net/1vgcs4we/

However when i implement it into my project i get the following error message:

Syntax Error: Token 'node.click' is unexpected, expecting [:] at column 3 of the expression [{{node.click}}] starting at [node.click}}].

The result i get is i can see the menu item names but when i hover over them i receive an empty menu box?

Here is my 2 Directives with the HTML as well:

app.directive('navMenu', ['$parse', '$compile', function ($parse, $compile) {
    return {
        restrict: 'C', //Element
        scope: true,
        link: function (scope, element, attrs) {
            scope.selectedNode = null;

            scope.$watch(attrs.menuData, function (val) {

                var template = angular.element('<ul id="parentTreeNavigation"><li ng-repeat="node in ' + attrs.menuData + '" ng-class="{active:node.active && node.active==true, \'has-dropdown\': !!node.children && node.children.length}"><a ng-href="{{node.href}}" ng-click="{{node.click}}" target="{{node.target}}" >{{node.text}}</a><sub-navigation-tree></sub-navigation-tree></li></ul>');

                var linkFunction = $compile(template);
                linkFunction(scope);
                element.html(null).append(template);

            }, true);
        }
    };
}]);
app.directive('subNavigationTree', ['$compile', function ($compile) {
    return {
        restrict: 'E', //Element
        scope: true,
        link: function (scope, element, attrs) {
            scope.tree = scope.node;

            if (scope.tree.children && scope.tree.children.length) {
                var template = angular.element('<ul class="dropdown "><li ng-repeat="node in tree.children" node-id={{node.' + attrs.nodeId + '}}  ng-class="{active:node.active && node.active==true, \'has-dropdown\': !!node.children && node.children.length}"><a ng-href="{{node.href}}" ng-click="{{node.click}}" target="{{node.target}}" ng-bind-html-unsafe="node.text"></a><sub-navigation-tree tree="node"></sub-navigation-tree></li></ul>');

                var linkFunction = $compile(template);
                linkFunction(scope);
                element.replaceWith(template);
            } else {
                element.remove();
            }
        }
    };
}]);

app.controller('HeaderController', ['$scope', '$location', function ($scope, $location) { 
    $scope.breadcrumbs = [];
    $scope.menu = [{
        text: 'HOME',
        href: '/app/index.html',
        children: [{
            text: 'MANAGE Dashboard',
            href: '/dashb'
        }]
    }, {
        text: 'MANAGE',
        href: '/manage',
        children: [{
            text: 'MANAGE PEOPLE',
            href: '/manage-people',
            children: [{
                text: 'MANAGE STAFF',
                href: '/manage-staff'
            }, {
                text: 'MANAGE CLIENTS',
                href: '/manage-clients'
            }]
        }]
    }, {
        text: 'REPORTS',
        href: '/reports',
        children: [{
            text: 'REPORT NUMERO UNO',
            href: '#'
        }, {
            text: 'REP NUMERO 2',
            href: '#',
            children: [{
                text: 'Third Tier',
                href: '#'
            }, {
                text: 'Another Third Tier',
                href: '#',
                children: [{
                    text: 'SUB SUB NAV',
                    href: '#'
                }]
            }]
        }]
    }, {
        text: 'MY INFO',
        href: '/my-info'
    }, ]


}]);

<div class="row">
<div class="large-12 columns">

   <nav class="nav-menu" menu-data="menu"></nav>

</div>
</div>

解决方案

The problem is you are using ng-bind-html-unsafe which has been deprecated form Angular 1.2+, you should replace it with ng-bind-html then you need to sanitize that html using $sce service using $sce.trustedAsHtml method.

For that you should write your custom filter and apply that filter wherever you want display an HTML

app.filter('unsafe', function($sce) { 
    return $sce.trustAsHtml; 
});

Then in your html it would be used as ng-bind-html="node.text| unsafe"

Demo here

这篇关于角度错误我不明白?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆