简体   繁体   English

angularJs指令存在问题

[英]Problems with angularJs directives

I created angularjs directives: 我创建了angularjs指令:

'use strict';

angular.module('frontend')
    .directive('overall', function() {
        return {
            restrict: 'E',
            scope: {
                data: '=data'
            },
            templateUrl: 'app/components/overall/overall.html',
            controller: function($scope) {
               alert($scope.data)
            }
        };
    });

and template for him: 和他的模板:

<div id="inner-overall">
  Taras
</div>

After it in other page I use my directive like this: 在其他页面之后,我使用如下指令:

<overall data></overall>

and js code: 和js代码:

$scope.data = 'daadad';

But it is not working, and I catch empty $scope.data value. 但这不起作用,并且我捕获了空的$ scope.data值。 I don't know why it happens and how to fix it, help me please with this issue. 我不知道为什么会发生以及如何解决它,请帮我解决这个问题。 Thanks a lot! 非常感谢!

You didn't bind model that's why it's empty 您没有绑定模型,这就是它为空的原因

Try like this 这样尝试

<overall data="data"></overall>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM