<select name="Connection" class="mdl-button" id="dropConnection" onchange="connectionChange()" ></select>  

内容是从 JSON 响应自动添加的。工作正常。

function connectionChange() 
{ 
    var sel = document.getElementById("dropConnection"); 
    var connectionName = sel.options[sel.selectedIndex].text; 
  $scope.connectionDetail = response.data.message.connectionDetailses.filter(det => det.connectionId === connectionName); 
  console.log($scope.connectionDetail); 
} 

运行页面后,当我更改下拉内容时显示错误

home.html:265 Uncaught ReferenceError: $scope is not defined 
    at connectionChange (home.html:265) // above javascript code. 
    at HTMLSelectElement.onchange (VM4122 home.html:139) 

请您参考如下方法:

home.html:265 Uncaught ReferenceError: $scope is not defined 
    at connectionChange (home.html:265) // above javascript code. 
    at HTMLSelectElement.onchange (VM4122 home.html:139) 

查看此错误,可以推断您尚未在 Controller 中注入(inject) $scope。在 Controller 中注入(inject) $scope 即可解决此错误。

查看此处的链接,了解如何在 AngularJS 中正确创建 Controller AngularJS controller


评论关闭
IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!