如何在angularJs上使用onClick?

时间:2016-11-04 11:43:07

标签: angularjs

我写了条件

onclick="window.open({{video_call_url}}, '_system', 'location=yes'); return false;"

此处video_call_url在myController中定义为$scope.video_call_url = 'http://www.google.com/';

但是当我点击按钮时,我收到错误video_call_url is not defined.

2 个答案:

答案 0 :(得分:5)

您可以在控制器中执行逻辑:

function myController($scope, $window) {
    $scope.openVideoCallUrl = function() {
        $window.open($scope.video_call_url, "_system", "location=yes");
        return false;
    }
}

在你看来

<a ng-click="openVideoCallUrl()">Open!</a>

答案 1 :(得分:1)

您可以使用ng-click,而不是使用onclick

ng-click="open(video_call_url)"

$scope.open = function(url) {
  //inject $window inside controller.
  $window.open(url, '_system', 'location=yes');
  return false;
}