使用angular js从Document.ready调用函数

时间:2018-07-05 11:58:50

标签: angularjs

我有一个main.html,它在encMain的控制器范围内。该页面上有一些按钮

main.html
--------
<div ng-app="enc" ng-controller="encMain">
<input type="button" value="Click A" ng-click="A()" ></>
<input type="button" value="Click B" ng-click="B()"></>
<input type="button" value="Click C" ng-click="B()"></> 
</div>


main.js
-----
var app = angular.module('enc', []);
app.controller('encMain', function ($scope) {

$scope.A = function() { alert('A function is invoked') }

$scope.B = function() { alert('B function is invoked') }

$scope.C = function() { alert('C function is invokedl') }



}

单击按钮从html Page调用函数时,我没有任何问题。 但是,对于功能的示例说明,我需要在文档准备就绪(DOM可用)时调用以下函数。

$(document).ready(function() {

  --- updateA function will be invoked from some X page. 
  window.updateA = function(){
   $scope.A - function A to be called here. this is inside in the scope of encMain.
 }

 function UpdateBandC(){
   $scope.B - function B to be called here. this is inside in the scope of encMain 
   $scope.C - function C to be called here. this is inside in the scope of encMain.
  } 

 UpdateBandC() - Call to the above function UpdateBandC.
}

情况1.假设我有一个页面“ Y”,并且我将调用下面的“ updateA”函数。 我在调用该函数时没有任何问题。但是,一旦在内部调用该函数 我需要调用encMain范围内的“ A”函数。问题是我不知道如何从document.ready调用函数“ A”,或者如何获取作用域的引用,以及如何给出引用以调用函数A。

案例2。一旦DOM准备就绪,内部将需要调用“ B'和'C'函数在encMain范围内。问题是我不知道该怎么打 文档准备好时函数B和C的功能或如何获取范围的引用以及如何获取 给出引用以调用函数A和B。

谢谢。请忽略拼写错误。 请帮助

0 个答案:

没有答案
相关问题