Angular中的控制器问题

时间:2014-03-24 21:20:14

标签: javascript html5 angularjs cordova controller

我有一个简单的控制器..它打开了使用Phonegap inapp浏览器传递的url。它工作但不再工作了!

.controller('JobDetailCtrl', ['$scope', '$routeParams', 'Job', 'Profile',function ($scope, $routeParams, Job,Profile) {
  $scope.job = Job.get({jobId: $routeParams.jobId});
  $scope.url=$scope.job.url;
  $scope.read($scope.url);                           

  //Defining read function to open inapp browser
  $scope.read =function(url){
         console.log("myurl"+url);
         var ref = window.open(url, '_blank', 'location=yes,toolbar=yes');
         ref.addEventListener('exit', function() {  });
   };

当我调用此函数时,它失败了。它不会在控制台中打印任何内容。请帮忙。

由于

JS

1 个答案:

答案 0 :(得分:1)

你必须在调用之前定义函数...试试这个

.controller('JobDetailCtrl', ['$scope', '$routeParams', 'Job', 'Profile',function ($scope, $routeParams, Job,Profile) {

  //Defining read function to open inapp browser
  $scope.read =function(url){
  ......
 };

 $scope.read($scope.url); //<<--- Invoke read after defining it.