Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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函数(在HTML中)?_Javascript_Angularjs - Fatal编程技术网

Javascript 如何内联定义AngularJS函数(在HTML中)?

Javascript 如何内联定义AngularJS函数(在HTML中)?,javascript,angularjs,Javascript,Angularjs,在我的HTML页面中我有以下功能: <button ng-controller="getURL" ng-href="{{getLoginUrl}}">Login</button> <script src="js/app.js"></script> <script type="text/javascript"> function getURL($scope) { $scope

在我的HTML页面中我有以下功能:

    <button ng-controller="getURL" ng-href="{{getLoginUrl}}">Login</button>
    <script src="js/app.js"></script>
    <script type="text/javascript">
        function getURL($scope) {
            $scope.getLoginUrl = '/my-url';
        }
    </script>
但我得到了这个错误:

未捕获引用错误:未定义getURL


我在getURL控制器之后放置的所有控制器都不工作,并且我得到错误
参数'anotherController'不是函数,未定义

将函数声明移动到
app.js
之前,因为您尝试在声明之前使用函数

<script type="text/javascript">
   function getURL($scope) {
       $scope.getLoginUrl = '/my-url';
   }
</script>
<script src="js/app.js"></script>

函数getURL($scope){
$scope.getLoginUrl='/myurl';
}
<script type="text/javascript">
   function getURL($scope) {
       $scope.getLoginUrl = '/my-url';
   }
</script>
<script src="js/app.js"></script>