检查 URL.$valid (if then) inside AngularJS ng-click。如何?

Checking for URL.$valid (if then) inside inside AngularJS ng-click. How?

我正在 angular 应用程序中制作一个 URL 列表,大多数 URL 都会导致 https://example.io... 然而 select 很少有 URL,例如 https://example.io。我不想在每个对象中指定 URL...我只想验证 URL 然后用 http://https:// 打开网站取决于什么有效。

我正在使用 ng-click 并将其绑定到一个 window 打开 url 以及嵌套图像。

Index.html

    <head>
    <script src="js/shared/angular.min.js"></script>
    <link rel="stylesheet" href="css/row.css">
    </head>

    <body ng-app="MainApp">
      <div ng-controller="Main" ng-cloak>
        <div id="RowDiv">
          <button style="visibility: hidden; width: 25px;"></button>
          <a ng-repeat="r1 in r1s" ng-click="openurl(r1.url.$valid==true?r1.url:'https://' + r1.name + '.io')"  ng-cloak>
            <img ng-src="img/{{r1.name}}.png" height="40px">
            </a>
            <button style="visibility: hidden; width: 25px;"></button>
        </div>
    </div>

    <button id="LftBtn" style="z-index: 1000;" >
        <i id="L-Arrow"></i>
    </button>

    <button id="RgtBtn" style="z-index: 1000;" >
        <i id="R-Arrow"></i>
    </button>

    <script src="js/protractor.js"></script>
    <script src="js/row.js"></script>
    </body>

protractor.js

    var app = angular.module("MainApp", []);

    // - - app controllers - - \

    app.controller('Main', ['$scope', function($scope) {
      $scope.r1s = [
        {name: 'Surviv', url: 'https://google.com'},
        //Just a test, urls will be changed later
        {name: 'Zombsroyale'},
        {name: 'Bruh'},
        {name: 'Krunker'},
        {name: 'Shellshock'},
        {name: 'Diep'},
        {name: 'Tanked'},
        {name: 'Gats'},
        {name: 'Warbot'},
        {name: 'Counterstroke'}
      ];
      $scope.openurl = function(url){
        if(window.parent == window.top) {
          //If outside
          window.open(url, "_blank"});
        } else {
          //If inside
          window.open(url, '_parent');
        }
      };
    }]);

这里最主要的是url验证, 和 ng-click="openurl(r1.url.$valid == true ? 'http://' + r1.name '.io' : 'https://' + r1.name + '.io')"

我不知道为什么这不起作用,它会打开弹出窗口,但会完全忽略三元和 $valid 参数...
我试过交换
- .$valid==true
瓦特/
- .$valid==false
但我得到了相同的结果!为什么这不起作用?

关于 plunkr、jsfiddle 或 codepen 等的工作示例会很棒。

经过长时间的搜索... 我偶然发现了 This 网站... 实现后的代码如下所示:

Index.html changes

ng-click="openurl(r1.url.$valid==true?r1.url:'https://' + r1.name + '.io')"

ng-click="is_url(r1.name+'.io')"

protractor.js changes/ additions

{name: 'Surviv', url: 'https://google.com'},

{name: 'Surviv'},

主控制器内部:
添加:

$scope.is_url = function(str) {
        regexp =  /^(?:(?:https?|ftp):\/\/)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/;
        if (regexp.test('https://' + str))
        {
            chrome.windows.create({url: 'https://' + str, type: "popup"});
        }
        else
        {
            chrome.windows.create({url: 'http://' + str, type: "popup"});
        }
};

我之前用的是window.openexample/use
我已经将其更改为 chrome.windows.create
window.open -
一起使用 更改 {url: 'http://' + str, type: "popup"}{url: 'https://' + str, type: "popup"}

至:'http://' + str, "_blank"'https://' + str, "_blank".

这花了太多时间在谷歌上搜索...希望遇到此问题的其他每个人现在都能找到更简单的使用方法...