我试图在视频结束后执行一个功能,该功能在角度控制器内部。该函数被调用,但我收到错误说明:
ReferenceError: postVendor is not defined
这是调用javascript:
$.noConflict();
jQuery(document).ready(function ($) {
var api = flowplayer();
api.bind("finish", function (e, api) {
var data = "true";
var url = "someurlhere";
postVendor(url, data);
});
});
这是我的模块/控制器(同一个文件):
var registrationModule = angular.module('registrationModule', []);
registrationModule.controller("vendorCtrl", function ($scope, $http) {
$scope.postVendor = function (url, data) {
$http.post(url, data).success(function (data) { console.log(data) }).error(function (data) { console.log(data) });
};
});
在我的HTML中:
<html xmlns="http://www.w3.org/1999/xhtml" ng-app="registrationModule">
<body ng-controller="vendorCtrl">
我正在使用角度1.2.25。
关于如何正确调用函数的任何想法?
答案 0 :(得分:1)
1.请确保在angular.js
之前加载jQuery2.确保您的vendorCtrl返回$ scope.postVendor(您可以通过添加来实现):
return {
postVendor : $scope.postVendor
};
请参阅示例
$(document).ready(function () {
angular.element('#angularController').controller().doSomthing("Hello ", "from jquery")
});
var app = angular.module('app', []);
app.controller('firstCtrl', function($scope){
$scope.doSomthing = function(a,b){
alert(a+b);
};
return {
doSomthing: $scope.doSomthing
};
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="app" >
<div id="angularController" ng-controller="firstCtrl">
</div>
</body>
&#13;
$.noConflict();
jQuery(document).ready(function ($) {
var api = flowplayer();
api.bind("finish", function (e, api) {
var data = "true";
var url = "someurlhere";
angular.element('body').controller().postVendor(url, data);
});
});
有关详细信息,请参阅此处Call Angular JS from legacy code