小编Adr*_*ajs的帖子

Angularjs:表单验证和输入指令

我在AngularJS应用程序中创建了一个指令,该应用程序在我的应用程序中生成样式输入.它看起来像这样:

AC.directive('formInput',function ($compile) {
    return {
        transclude: true,
        replace: true,
        scope:{},
        templateUrl: '/views/partials/form/input.html',
        restrict: 'E',
        link: function(scope, element, attrs){

            scope.opts = attrs;

            if(attrs.ngModel){
                element.find('input').attr('ng-model', attrs.ngModel);
                $compile(element.contents())(scope.$parent);
            }

            if(!attrs.type){
                scope.opts.type = 'text';
            }
        }
    };
  }
)
Run Code Online (Sandbox Code Playgroud)

它的模板是:

<label class="acxm-textfield {{opts.cssclass}}">
  <span ng-bind="opts.labeltext"></span>
  <input type="{{opts.type}}" name="{{opts.inputname}}" value="{{opts.inputvalue}}" placeholder="{{opts.placeholder}}" ng-maxlength="{{opts.maxLength}}"/>
</label>
Run Code Online (Sandbox Code Playgroud)

电话很简单:

<form-input ng-model="UserProfile.FirstName" max-length="50" labeltext="{{'GENERAL.name' | translate}}" cssclass="acxm-p-horizontal" inputname="name" inputvalue="{{UserProfile.FirstName}}"></form-input>
Run Code Online (Sandbox Code Playgroud)

我想为这个字段创建验证,我添加了一个错误信息:

<span ng-show="showError(userInfoForm.name,'email')">
                    You must enter a valid email
</span>
Run Code Online (Sandbox Code Playgroud)

并且showError是:

$scope.showError = function(ngModelController, error) {

    return ngModelController.$error[error];
};
Run Code Online (Sandbox Code Playgroud)

基本上,它是从"使用AngularJS掌握Web应用程序开发"一书中复制的.我有一个问题,因为当我记录我的表单时userInfoForm …

html javascript validation angularjs

5
推荐指数
1
解决办法
2万
查看次数

d3路径梯度行程

您好我正在使用d3对角线图,并希望添加一个渐变到链接我的圈子的路径...

我正在生成我的树:

            var width = 800,
                height = 700;

            element.html('');
            var color = d3.interpolateLab("#008000", "#c83a22");
            var scale = d3.scale.linear().domain([0, 100]).range(["red", "green"]);
            var cluster = d3.layout.cluster()
                .size([height, width - 160]);

            var diagonal = d3.svg.diagonal()
                .projection(function(d) { return [d.y, d.x]; });

            var svg = d3.select('#tab-manageAccess').append('svg')
                .attr('width', width)
                .attr('height', height)
                .append('g')
                .attr('transform', 'translate(40,0)');


            /*svg.append("linearGradient")
                .attr("id", "line-gradient")
                .attr("gradientUnits", "userSpaceOnUse")
                .attr("x1", 0).attr("y1", y(0))
                .attr("x2", 0).attr("y2", y(1000))
                .selectAll("stop")
                .data([
                    {offset: "0%", color: "red"},
                    {offset: "40%", color: "red"},
                    {offset: "40%", color: "black"},
                    {offset: "62%", color: "black"},
                    {offset: …
Run Code Online (Sandbox Code Playgroud)

javascript d3.js

3
推荐指数
1
解决办法
4110
查看次数

标签 统计

javascript ×2

angularjs ×1

d3.js ×1

html ×1

validation ×1