繁体   English   中英

AngularJS / Javascript下拉“ onchange”功能不起作用

[英]AngularJS/Javascript dropdown “onchange” function is not working

<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)

查看此错误,可以推断出您尚未在控制器中注入$scope 在您的控制器中注入$scope ,它将解决此错误。

在此处查看链接,以了解如何正确地在AngularJS中创建控制器AngularJS控制器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM