Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS href未获取动态值_Javascript_Angularjs_Html - Fatal编程技术网

Javascript AngularJS href未获取动态值

Javascript AngularJS href未获取动态值,javascript,angularjs,html,Javascript,Angularjs,Html,javascript代码: cable.register.controller('VideoMonitorCtrl', ['$scope', '$sce','ENV', '$http', function ($scope, $sce, ENV, $http) { console.log('Begin in video monitor controller'); var keepGoing =true; var url = '/ps/featu

javascript代码:

 cable.register.controller('VideoMonitorCtrl', ['$scope', '$sce','ENV', '$http', function ($scope, $sce, ENV, $http) {
        console.log('Begin in video monitor controller');

         var keepGoing =true;
        var url = '/ps/features/';
        var exists = false;
        $scope.getVideoService = function () {
        console.log("url"+$scope.hurl)
        $http.get(url,{headers: {'contentType': 'application/json; charset=UTF-8'}}).success( function(response) {  
        if(response!='') 
        {
            angular.forEach(response.features, function(feature){
                console.log("in for each");
                console.log(counter++)
            if(keepGoing) 
            {      
                if(feature.name.trim() === "odl-video-monitor" && feature.installed.trim() ==='x')
                {  
                    console.log('in active again');
                    $scope.color='#FFFFFF';
                    $scope.msg='Quality Network';
                    $scope.hurl='index.html#/cable/videomonitor';
                    exists=true;
                    keepGoing = false;
                }

            }
            });   
            if(!exists)
            {
                $scope.color='#BDBDBD';  
                $scope.msg='Video Quality Network is under maintenance';
            }
        }
        else 
        {
            $scope.color='#BDBDBD';  
             $scope.msg='Video Quality Network is under maintenance';
        }
        }).error(function (response) {
                 $scope.color='#BDBDBD';
                 $scope.msg='Video Quality Network is under maintenance';    
          });
         };   

     }
  ]);
<a ng-href='{{hurl}}'  ng-controller="VideoMonitorCtrl" ng-init="getVideoService()"  id="hlink" style="text-decoration:none;">    
       <div class="box" style="background-color:{{color}};">
         <div style="margin-top:15px;text-align:left;padding-left:23px;">
          <span style="font-size:24px !important;font-family:Times New Roman, serif;color:#7B7B7B;" class="Large">{{msg}}
             {{hurl}}
             </span>
         </div>
      </div>
        </a>
HTML代码:

 cable.register.controller('VideoMonitorCtrl', ['$scope', '$sce','ENV', '$http', function ($scope, $sce, ENV, $http) {
        console.log('Begin in video monitor controller');

         var keepGoing =true;
        var url = '/ps/features/';
        var exists = false;
        $scope.getVideoService = function () {
        console.log("url"+$scope.hurl)
        $http.get(url,{headers: {'contentType': 'application/json; charset=UTF-8'}}).success( function(response) {  
        if(response!='') 
        {
            angular.forEach(response.features, function(feature){
                console.log("in for each");
                console.log(counter++)
            if(keepGoing) 
            {      
                if(feature.name.trim() === "odl-video-monitor" && feature.installed.trim() ==='x')
                {  
                    console.log('in active again');
                    $scope.color='#FFFFFF';
                    $scope.msg='Quality Network';
                    $scope.hurl='index.html#/cable/videomonitor';
                    exists=true;
                    keepGoing = false;
                }

            }
            });   
            if(!exists)
            {
                $scope.color='#BDBDBD';  
                $scope.msg='Video Quality Network is under maintenance';
            }
        }
        else 
        {
            $scope.color='#BDBDBD';  
             $scope.msg='Video Quality Network is under maintenance';
        }
        }).error(function (response) {
                 $scope.color='#BDBDBD';
                 $scope.msg='Video Quality Network is under maintenance';    
          });
         };   

     }
  ]);
<a ng-href='{{hurl}}'  ng-controller="VideoMonitorCtrl" ng-init="getVideoService()"  id="hlink" style="text-decoration:none;">    
       <div class="box" style="background-color:{{color}};">
         <div style="margin-top:15px;text-align:left;padding-left:23px;">
          <span style="font-size:24px !important;font-family:Times New Roman, serif;color:#7B7B7B;" class="Large">{{msg}}
             {{hurl}}
             </span>
         </div>
      </div>
        </a>

输出:

{{hurl}
=>正在打印div中的值

此处的Hull中没有值,链接未启用

有什么原因吗?我可以在div中看到投掷内容,但在href中看不到

如果我在href中写入硬编码的值,它可以工作,但不是动态的?

将整个


视频监视器Ctrl
的父项范围内。将
ng控制器
移动到
@charlietfl的父级,为什么它在这个plnkr中工作?哈哈哈。。我试着把同样的东西放在内分区。我没有尝试outer div。谢谢您的回复。没问题:)您可能还想重组您的项目,这里有一个很好的例子:@user2773086为什么这样做有效?