如何将多个值(字符串、数字、数组等)传递给 angularjs 中的元素指令

How to pass more than one values(string,numeric,array etc) to Element Directive in angularjs

我将在另一个 html 中使用该指令,并将这四个值(字符串、整数、数组等)绑定到该指令,但我无法获取这些绑定值。 以下是我尝试获取的代码。

(function () {

"use strict";

angular.module('common').directive('monitoringmenu', ['$rootScope', '$compile',
    function ($rootScope, $compile) {
        var directive = {
            restrict: 'E',
            scope: {
                entityType: '@',
                entityIds: '@',
                selectedEntityId: '@',
                isOpen: '@'
            },
            link: link,
            templateUrl: './Templates/CommonMenuTemplate.html',
        };
        return directive;

        function link(scope, el, attrs) {
            $compile(attrs.isOpen);
        }
    }]);

})();

基本上不需要$compile。 Example

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
})
.directive('monitoringMenu', ['$rootScope', '$compile',
    function ($rootScope, $compile) {
        return {
            restrict: 'E',
            scope: {
                entityType: '@',
                entityIds: '@',
                selectedEntityId: '@',
                isOpen: '@'
            },
            link: function(scope, elem, attrs){
              console.log(scope);
            },
            templateUrl: 'template.html',
        };
    }]);

HTML

<monitoring-menu entity-type="asdfg" entity-ids="1" selected-entity-id="1" is-open="true"></monitoring-menu>

HTML 模板

<div>entityType:{{entityType}}</div><br>
<div>entityIds:{{entityIds}}</div><br>
<div>selectedEntityId:{{selectedEntityId}}</div><br>
<div>isOpen:{{isOpen}}</div><br>

我派了一个plunkr来看看。