gpt4 book ai didi

javascript - angularjs Controller 功能不起作用

转载 作者:行者123 更新时间:2023-11-28 07:10:54 27 4
gpt4 key购买 nike

我正在使用该函数,并且想要使用 Controller 函数“dayResult()”计算日期差,但是如果我在其中编写代码, Angular 函数将停止工作。任何人都可以告诉我如何获得结果通过dayresult()函数

.html 文件

  <html>
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" media="screen" href="http://tarruda.github.com/bootstrap-datetimepicker/assets/css/bootstrap-datetimepicker.min.css">

<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js">
</script>
<script type="text/javascript" src="http://tarruda.github.com/bootstrap-datetimepicker/assets/js/bootstrap-datetimepicker.min.js">
</script>
<script data-require="angular.js@1.0.x" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js" data-semver="1.0.8"></script>


<script src="app.js"></script>
</head>

<body>
<div ng-app="plunker" class="container container-fluid" ng-controller="MainCtrl">

<!-- <form class="form-horizontal" novalidate name="form" ng-submit="submit()">
<div class="well">-->

<div id="date" class="input-append" datetimez ng-model="var1">
<input data-format="MM-dd-yyyy" type="text" id="input1" name="input1"></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>



<div id="date" class="input-append" datetimez ng-model="var2">
<input data-format="MM-dd-yyyy" type="text" id="input1" name="input1" ></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</span>
</div>

<!-- </div>
</form>-->
var1={{var1}}
<br>
var2={{var2}}
<br>
<!-- here is day result function -->
difference= {{dayResult()}} days
</div>
<script>
var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
$scope.dayResult = function()
{

}

});

app.directive('datetimez', function() {
return {
restrict: 'A',
require : 'ngModel',
link: function(scope, element, attrs, ngModelCtrl) {
element.datetimepicker({
dateFormat:'dd-MM-yyyy',
language: 'en',
pickTime: true,
startDate: '01-11-2013', // set a minimum date
endDate: '01-11-2030' // set a maximum date
}).on('changeDate', function(e) {
ngModelCtrl.$setViewValue(e.date);
scope.$apply();
});
}
};
});
</script>
</body>
</html>

最佳答案

添加返回值并不能解决问题?

$scope.dayResult = function() 
{
return "test";
}

关于javascript - angularjs Controller 功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31309802/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com