Javascript 在HTML5的匿名函数中定义的访问控制器函数
我已经定义了app.js来调用Some-View.View.html和Some-View-controller.js。Some-View.View.html具有ng click指令来调用Some-View-controller.js中定义的函数 使用ng click指令单击元素后,不会调用Some-View-controller.js中定义的函数 请告诉我如何调用Some-View-controller.js中定义的函数,以及如何访问链接到ng模型的变量 app.jsJavascript 在HTML5的匿名函数中定义的访问控制器函数,javascript,angularjs,html,Javascript,Angularjs,Html,我已经定义了app.js来调用Some-View.View.html和Some-View-controller.js。Some-View.View.html具有ng click指令来调用Some-View-controller.js中定义的函数 使用ng click指令单击元素后,不会调用Some-View-controller.js中定义的函数 请告诉我如何调用Some-View-controller.js中定义的函数,以及如何访问链接到ng模型的变量 app.js .when('/S
.when('/Some-View', {
controller: 'SomeViewController',
templateUrl: 'Some-View/Some-View.view.html',
controllerAs: 'vm'
})
(function () {
'use strict';
angular
.module('app')
.controller('SomeViewController', SomeViewController);
SomeViewController.$inject = ['UserService', '$rootScope'];
function SomeViewController(UserService, $rootScope) {
/*Discussion Board related Functions*/
var vm = this;
/////
vm.comments = [];
vm.currCmtIndx=-1;
vm.userReply="";
function functionToBeCalledFrom_NG_CLICK() {
}
}
/*End - Discussion Board related Functions*/
} /*End - SomeViewController */
})();
一些视图控制器.js
.when('/Some-View', {
controller: 'SomeViewController',
templateUrl: 'Some-View/Some-View.view.html',
controllerAs: 'vm'
})
(function () {
'use strict';
angular
.module('app')
.controller('SomeViewController', SomeViewController);
SomeViewController.$inject = ['UserService', '$rootScope'];
function SomeViewController(UserService, $rootScope) {
/*Discussion Board related Functions*/
var vm = this;
/////
vm.comments = [];
vm.currCmtIndx=-1;
vm.userReply="";
function functionToBeCalledFrom_NG_CLICK() {
}
}
/*End - Discussion Board related Functions*/
} /*End - SomeViewController */
})();
HTML代码片段
<div class="form-group" >
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-success btn-circle text-uppercase" type="button" id="submitComment" ng-click="vm.functionToBeCalledFrom_NG_CLICK()"><span class="glyphicon glyphicon-send" id="qazwsx"></span> Summit comment</button>
</div>
</div>
峰会评论
非常抱歉让您注意到这个小问题。我没有将var分配到控制器中,以使HTML能够调用它。我添加了vm.functionToBeCalledFrom\u NG\u CLICK=functionToBeCalledFrom\u NG\u CLICK;现在可以调用它了!如果你不需要帮助,你可以删除这个问题。我想,这个问题可以被声誉超过10K的会员删除。请让我知道我是否可以自己删除它