Javascript 角度js中的GetElementById等价

Javascript 角度js中的GetElementById等价,javascript,angularjs,Javascript,Angularjs,我只想要angular js中的点击事件。谁能说出来 我只想要angular js中的点击事件。 谁能说出来? 代码在注释中这不是角度的方式,DOM应该在代码中调用函数,而不是在DOM中轮询事件 <div> <input id="txt" type="text" placeholder="Choose File" /> <input type="file" id="selectedFile" class="hidden" onchange="Cha

我只想要angular js中的点击事件。谁能说出来

我只想要angular js中的点击事件。 谁能说出来?
代码在注释中

这不是角度的方式,DOM应该在代码中调用函数,而不是在DOM中轮询事件

<div>
    <input id="txt"  type="text" placeholder="Choose File" />
    <input type="file" id="selectedFile" class="hidden" onchange="ChangeText(this, 'txt');" />
    <span>
        <button type="button" onclick="document.getElementById('selectedFile').click();">Browse</button>
    </span>
</div>
编辑: 因为我现在只看到你的代码,你展示的代码不是角度代码。如果要使用angular,请查看以下链接:


我更喜欢codeschool让您开始学习,因为它更具交互性,并且提供了一个循序渐进的指南。

好的,在我可能没有完全阅读您的问题之前。现在我有了,我想这就是你想要的:

function MyButtonController() {
  this.doTheThing = function() {
    alert('I\'m doing the thing!')
  };
}
在指令的link函数中,我将输入注入控制器。控制器只需向节点触发一个click事件,从而调用文件浏览器

编辑:我个人不会使用输入来显示文件,而是显示所有选定文件的更通用的列表,如果可能的话,还可以进行预览。这样,您只需使用第一个输入:


很抱歉没有更好地阅读您的问题,希望这对您有所帮助。

浏览请更清楚地描述问题。如果你想在angular中单击事件,那么需要使用ngclick事件我的代码是js的,对于browse button,我已经给出了onclick事件,这样它就可以像这样获取selectedfile id元素,浏览以便在angular JS中使用该函数我不想在angular JS中使用document.getElementById而不是getElementById,如果没有,我可以在函数中写些什么。您应该使用控制器编写一个指令,只需从DOM中调用控制器的函数即可。当使用angular时,您不应该在代码中使用DOMNode。可能会有一些例外情况,但始终不要在控制器中引用DOM。在函数中使用document.getElementById'selectedFile'。单击。我们可以不使用getElementByID执行相同的功能吗
<my-button  ng-click="{{ MyBtnCtrl.doTheThing() }}">Do the thing!</my-button>
function MyButtonController() {
  this.doTheThing = function() {
    alert('I\'m doing the thing!')
  };
}
<div>
    <input id="txt"  type="text" placeholder="Choose File" />
    <input type="file" id="selectedFile" class="hidden" onchange="ChangeText(this, 'txt');" />
    <span>
        <button type="button" onclick="click();">Browse</button>
    </span>
</div>

$scope.click = function() {
        document.getElementById('selectedFile').click()
};
.controller('Upload', ['$scope', function($scope) {
    this.input;

    this.browse = function() {
        this.input.click();
    };
}])
.directive('fileUpload', [function() {
    return {
        'restrict':'E',
        'controller':'Upload',
        'controllerAs':'upload',
        'templateUrl': './upload.html',
        'link':function($scope, $element, $attribute, upload) {
            upload.input = $element.find('input')[1];
        }
    };
}]);