ng-click在div中不起作用

时间:2017-07-24 17:01:34

标签: javascript angularjs angularjs-ng-click

我已经被困在这里一段时间,当我使用" form"标签一切都好,但在" div"标签......

main.js:

reader = open('symbols','r')
refile = reader.readlines()
for sim in refile:
    quotes = json.dumps(getQuotes([sim]))
    data = json.loads(quotes)

    for item in data:
        for k, v in item.items():
            #if "LastTradePrice" in k:
                print k, v

的index.html:

var app = angular.module('demo', []);

app.controller('appctrl', function ($scope) {    
    $scope.start = function (name) {
        console.log(name);}
 }

2 个答案:

答案 0 :(得分:3)

我认为你需要这个,你需要将函数命名为 show ,你还需要将参数传递给函数show。

此外,您在控制器中缺少 )

app.controller('appctrl', function ($scope) {    
    $scope.show = function (name) {
        console.log(name);}
 }

<强>样本

&#13;
&#13;
var app = angular.module('demo', []);

app.controller('appctrl', function ($scope) {    
    $scope.start = function (name) {
        console.log(name);
        }
        
});
&#13;
<!DOCTYPE html>
<html ng-app="demo">
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>
    </head>
    <body>
        <div id="container" ng-controller="appctrl">
            <input id="input" autocorrect="off" spellcheck="false" autocapitalize="off" autofocus="true" placeholder="Please enter your full name" type="text" ng-model="name">
            <div id="button" ng-click="start('TEST')">Start Demo</div>
        </div>
    </body>
</html>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

app.controller('appctrl', function ($scope) { 
    $scope.name = null;   
    $scope.show = function (name) {
        console.log(name);
    }
});
<div id="container" ng-controller="appctrl">
            <input id="input" autocorrect="off" spellcheck="false" autocapitalize="off" autofocus="true" placeholder="Please enter your full name" type="text" ng-model="name">
            <div id="button" ng-click="show(name)">Start Demo</div>
        </div>

您正在调用show(),但您定义了start()