为什么变量指令控制器定义不工作? [英] Why variable defined in the directive controller not working?

查看:152
本文介绍了为什么变量指令控制器定义不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我定义'的sayHi'在控制器,它不会在模板中显示

Why i defined 'sayHi' in the controller, and it does not display in the template?

JS:

(function(){
var app = angular.module('myApp', []);

app.directive("directive1", function(){
    return {
        restrict : 'E',
        scope: {

        },
        link : function($scope){        

        },

        controller: ['$scope', function($scope){
          $scope.sayHi = 'hi';
          window.console.log($scope.sayHi);
        }]

    };  
});
})();

HTML:

<div style="border: 1px solid; padding: 10px; min-height: 100px;">
Directive1 :   
<directive1>
    {{sayHi}}
</directive1>
</div>

详细plnkr

推荐答案

您的指令没有任何模板。您需要添加

Your directive doesn't have any template. You need to add

template: '{{ sayHi }}',

要你的指令定义。里面的内容&LT;&指令1 GT;&LT; /指令方式&gt; 不构成指令的模板

To your directive definition. The content inside the <directive1></directive> does not constitute the template of the directive.

这篇关于为什么变量指令控制器定义不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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