获取没有方法错误AngularJS Bootstrap HTML

时间:2014-01-15 23:33:09

标签: javascript html angularjs twitter-bootstrap

调用此方法时,我得到一个没有方法错误$ scope.getImageReturn();

    JS CODE
function imageModalController($scope, $http, employeeFactory, $modalInstance) {

$scope.session = {};
$scope.getImageReturn();
$scope.cancel = function() {

    $modalInstance.dismiss('cancel');
};

$scope.signUp = function() {
    // alert("call signUp");
    window.location = "index.html#/signUp";
};

$scope.getImage = function(email) {

    employeeFactory.getImage(mail);

};
$scope.getImageReturn = function() {
    $scope.session.img_source = "test";
        //data.path;
};

}

HTML CODE

    <div class="modal-body">
<div class="panel panel-info">

    <div class="panel-heading">Attachment</div>
    <div class="panel-body">

        <label>{{img_source}}</label>
    </div>

</div>

当未调用getImageReturn时,将弹出模态。所以我知道它只是具有该功能的事实。不知道为什么会发生这种情况并且真的无法想到为什么会这样做的原因

2 个答案:

答案 0 :(得分:2)

只需将{{img_source}}替换为{{session.img_source}},因为img_source未直接附加到$scope

实际上,数据绑定括号允许您省略$scope,但不能省略$scope与目标之间的中间对象。

答案 1 :(得分:2)

在调用方法之前,将此声明移动到控制器的顶部。

$scope.getImageReturn = function() {
    $scope.session.img_source = "test";
        //data.path;
};