Angular 将变量发送到指令

Angular1 Send Variable to directive

如何将变量发送到指令?我的代码实际上不起作用,但我根据您的评论做了所有事情:( 正如您在我的 .html 文件中看到的那样,{{ ctrl.emptyParent.name }} 正在运行。

.html

<div cms-dropdown emptyParent="emptyParent.name" classes="btn-default">
    <i style="opacity: 0.8">{{ emptyParent.name }}</i>
</div>

指令

.directive('cmsDropdown', [function(){
    return {
        restrict: 'A',
        scope: {
            emptyParent: '=',
        },
        transclude: true,
        template:
            `
            {{emptyParent}} Hi

            `
        link: function($scope, $element, $attrs){

        }
    };
}]);

和变量

this.emptyParent = {
    _id: 'empty',
    name: '~~#(brak)#~~',
    parentAlbumId: null,
    position: -1,
    createdDate: undefined,
    modifiedDate: undefined
};

emptyParent="emptyParent.name"更改为empty-parent="emptyParent.name"

angular.module("app",[])
.controller("ctrl",function($scope){
 $scope.emptyParent = {"name":"jhon"}
})
.directive('cmsDropdown', [function(){
    return {
        restrict: 'A',
        scope: {
            emptyParent: '=',
        },
        transclude: true,
        template:
            `
            {{emptyParent}} Hi
              
            `,
        link: function($scope, $element, $attrs){

        }
    };
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<div cms-dropdown empty-parent="emptyParent.name" classes="btn-default">
    <i style="opacity: 0.8">{{ emptyParent.name }}</i>
</div>
</div>