【问题标题】:Getting has no method error AngularJS Bootstrap HTML获取没有方法错误AngularJS Bootstrap HTML
【发布时间】:2014-01-15 23:33:09
【问题描述】:

调用此方法 $scope.getImageReturn(); 时出现 has no method 错误;

    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 代码

    <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 时会弹出模态框。所以我知道一个事实,它只是具有那个功能。不知道为什么会发生,而且真的想不出原因

【问题讨论】:

    标签: javascript html angularjs twitter-bootstrap


    【解决方案1】:

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

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

    【讨论】:

    • 泰。我的问题总是那么基本,复杂的我可以轻松解决,“基本”的问题让我有点
    【解决方案2】:

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

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

    【讨论】:

    • 这对解决问题没有帮助,但它确实有助于解决潜在的未来问题,所以谢谢
    • 我只是用了他的,它按照我想要的方式工作,会话的东西来自我以前使用的代码并且不想再使用它我很欣赏这两个答案。泰
    猜你喜欢
    • 2012-09-24
    • 2013-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多