AngularJs 不使用 umbraco 插件调用控制器
AngularJs doesn't call controller with umbraco plugin
我是 AngularJS 的新手。
我正在尝试为文本区域中的字符限制做一个 Umbraco 插件,但我在调用控制器中的函数时遇到问题。我的控制器是
angular.module("umbraco").controller("Example.CharLimitController", function ($scope) {
alert("0");
$scope.limitchars = function () {
alert("1");
var limit = 30;
if ($scope.module.value.length > limit) {
$scope.info = 'You cannot write more than ' + (limit) + ' Characters ';
$scope.module.value = $scope.module.value.substr(0, limit);
}
else
{ $scope.info = 'You have ' + (limit - $scope.model.value.length) + ' Characters left';}
}
});
我正在从
调用控制器
<div ng-controller="Example.CharLimitController">
<textarea cols="10" ng-model="model.value" ng-change="limitchars"></textarea>
<br/>
<span ng-bind="info"></span>
</div>
当我加载页面时显示 Alert(0),但在更改文本区域时 Alert(1) 没有显示,下面也没有任何内容。
请帮忙
ng 更改的语法是:
ng-change =limitChars()
我在你的构造函数中看不到任何模型对象。
你能把它改成模型并检查吗?
<div ng-controller="Example.CharLimitController">
<textarea cols="10" ng-model="model" ng-change="limitchars()"></textarea>
<br/>
<span ng-bind="info"></span>
</div>
angular.module("umbraco", []).controller("Example.CharLimitController", ['$scope', function($scope) {
$scope.limitchars = function() {
var limit = 3;
if ($scope.model.value.length > limit) {
$scope.info = 'You cannot write more than ' + (limit) + ' Characters ';
$scope.model.value = $scope.model.value.substr(0, limit);
} else {
$scope.info = 'You have ' + (limit - $scope.model.value.length) + ' Characters left';
}
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.4/angular.min.js"></script>
<div ng-app="umbraco">
<div ng-controller="Example.CharLimitController"> <textarea cols="10" ng-model="model.value" ng-change="limitchars()"></textarea> <br/> <span ng-bind="info"></span> </div>
</div>
我是 AngularJS 的新手。 我正在尝试为文本区域中的字符限制做一个 Umbraco 插件,但我在调用控制器中的函数时遇到问题。我的控制器是
angular.module("umbraco").controller("Example.CharLimitController", function ($scope) {
alert("0");
$scope.limitchars = function () {
alert("1");
var limit = 30;
if ($scope.module.value.length > limit) {
$scope.info = 'You cannot write more than ' + (limit) + ' Characters ';
$scope.module.value = $scope.module.value.substr(0, limit);
}
else
{ $scope.info = 'You have ' + (limit - $scope.model.value.length) + ' Characters left';}
}
});
我正在从
调用控制器<div ng-controller="Example.CharLimitController">
<textarea cols="10" ng-model="model.value" ng-change="limitchars"></textarea>
<br/>
<span ng-bind="info"></span>
</div>
当我加载页面时显示 Alert(0),但在更改文本区域时 Alert(1) 没有显示,下面也没有任何内容。
请帮忙
ng 更改的语法是:
ng-change =limitChars()
我在你的构造函数中看不到任何模型对象。
你能把它改成模型并检查吗?
<div ng-controller="Example.CharLimitController">
<textarea cols="10" ng-model="model" ng-change="limitchars()"></textarea>
<br/>
<span ng-bind="info"></span>
</div>
angular.module("umbraco", []).controller("Example.CharLimitController", ['$scope', function($scope) {
$scope.limitchars = function() {
var limit = 3;
if ($scope.model.value.length > limit) {
$scope.info = 'You cannot write more than ' + (limit) + ' Characters ';
$scope.model.value = $scope.model.value.substr(0, limit);
} else {
$scope.info = 'You have ' + (limit - $scope.model.value.length) + ' Characters left';
}
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.4/angular.min.js"></script>
<div ng-app="umbraco">
<div ng-controller="Example.CharLimitController"> <textarea cols="10" ng-model="model.value" ng-change="limitchars()"></textarea> <br/> <span ng-bind="info"></span> </div>
</div>