绑定指令/控制器中的$ scope

时间:2015-05-05 12:29:42

标签: angularjs scope controllers

将一个示波器绑定到我的指令/控制器之后我再也不能使用它自己的指令了,有什么我应该修复的吗?到目前为止,我试图找到一个答案,但没什么。

ANGULARJS:

return {
        scope: { fullpost:'@' },
        controller: function ($scope, $element) {

            // Edit Btn
            $scope.editbtn = "Edit";
$ scope.editbtn不再显示在html中。

HTML:

<full-post fullpost="fullpost">
<!-- edit tools -->
<div class='yardtools'>
<button id='edit' ng-click='edit()'><i class='fa fa-pencil-square-o'></i> {{ editbtn }}</button>
<button id='update' class='hidden'><i class='fa fa-wrench'></i> Update</button>
<button id='delete'ng-click='delete()'class='hidden'><i class='fa fa-trash-o'></i> Delete</button>
    </div>
<!-- post -->
<div class='yardman-post' data-post-id=" + id + ">
    <div ym='info'>
        <p>Post id: <em> {{ fullpost.id }}</em>, Posted on: <em>{{ fullpost.date }}</em>, by <em>AUTHOR</em>
        </p>
    </div>
    <div ym='title' contenteditable='false'>{{ fullpost.title }}</div>
    <div ym='body' contenteditable='false'>{{ fullpost.text }}</div>
</div>
</full-post>

1 个答案:

答案 0 :(得分:0)

我建议你将你的内部html放到指令元素中将其移动到某个模板,虽然可以选择使用ng-transclude但是在查看你当前的html时你可以使用内部内容使用模板和指令的指令使用templateUrl访问该模板。

<强> directiveTemplate.html

<div class='yardtools'>
<button id='edit' ng-click='edit()'><i class='fa fa-pencil-square-o'></i> {{ editbtn }}</button>
<button id='update' class='hidden'><i class='fa fa-wrench'></i> Update</button>
<button id='delete'ng-click='delete()'class='hidden'><i class='fa fa-trash-o'></i> Delete</button>
    </div>
<!-- post -->
<div class='yardman-post' data-post-id=" + id + ">
    <div ym='info'>
        <p>Post id: <em> {{ fullpost.id }}</em>, Posted on: <em>{{ fullpost.date }}</em>, by <em>AUTHOR</em>
        </p>
    </div>
    <div ym='title' contenteditable='false'>{{ fullpost.title }}</div>
    <div ym='body' contenteditable='false'>{{ fullpost.text }}</div>
</div>

<强>指令

return {
    scope: { fullpost:'@' },
    templateUrl: 'directiveTemplate.html'
    controller: function ($scope, $element) {

        // Edit Btn
        $scope.editbtn = "Edit";
     }
 }