简体   繁体   English

如何在我的 angularjs 应用程序中使用 jsfiddle 代码

[英]how to use jsfiddle code in my angularjs application

I have to use this jsfiddle code in my application, as I am going to enter all the code in one page company.html, it shows me only this我必须在我的应用程序中使用这个jsfiddle 代码,因为我将在一页 company.html 中输入所有代码,它只显示我这个输出 instead of this而不是这个输出 . . Could anybody please explain me why is this problem occuring, i think the problem is with this谁能解释一下为什么会出现这个问题,我认为问题出在这个

var app = angular.module('angularjs-starter', []);

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

$scope.choices = [{id: 'choice1'}, {id: 'choice2'}];

$scope.addNewChoice = function() {
var newItemNo = $scope.choices.length+1;
$scope.choices.push({'id':'choice'+newItemNo});
};

$scope.removeChoice = function() {
var lastItem = $scope.choices.length-1;
$scope.choices.splice(lastItem);
};

});

regarding to module name or kind of that.关于模块名称或类型。 I am getting this error in browser console:我在浏览器控制台中收到此错误: 在此处输入图片说明

You are getting error because of your Immediately Invoked Function Expression .由于您的“ Immediately Invoked Function Expression ,您收到错误消息。 you have to change it like below :你必须像下面那样改变它:

 /* ------------------------------------------------------- * Filename: Adding Form Fields Dynamically * Website: http://www.shanidkv.com * Description: Shanidkv AngularJS blog * Author: Muhammed Shanid shanidkannur@gmail.com ---------------------------------------------------------*/ var app = angular.module('angularjs-starter', []); app.controller('MainCtrl', function($scope) { $scope.choices = [{ id: 'choice1' }, { id: 'choice2' }]; $scope.addNewChoice = function() { var newItemNo = $scope.choices.length + 1; $scope.choices.push({ 'id': 'choice' + newItemNo }); }; $scope.removeChoice = function() { var lastItem = $scope.choices.length - 1; $scope.choices.splice(lastItem); }; })(angularjs-starter);
 fieldset { background: #FCFCFC; padding: 16px; border: 1px solid #D5D5D5; } .addfields { margin: 10px 0; } #choicesDisplay { padding: 10px; background: rgb(227, 250, 227); border: 1px solid rgb(171, 239, 171); color: rgb(9, 56, 9); } .remove { background: #C76868; color: #FFF; font-weight: bold; font-size: 21px; border: 0; cursor: pointer; display: inline-block; padding: 4px 9px; vertical-align: top; line-height: 100%; } input[type="text"], select { padding: 5px; }
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-app="angularjs-starter" ng-controller="MainCtrl"> <fieldset data-ng-repeat="choice in choices"> <select> <option>Mobile</option> <option>Office</option> <option>Home</option> </select> <input type="text" ng-model="choice.name" name="" placeholder="Enter mobile number"> <button class="remove" ng-show="$last" ng-click="removeChoice()">-</button> </fieldset> <button class="addfields" ng-click="addNewChoice()">Add fields</button> <div id="choicesDisplay" style="visibility:hidden;"> </div> </div>

If you Need the choices display to come up just let me know.如果您需要显示选项,请告诉我。 Will add that!会加的! Just copy the code and you are good to go.只需复制代码即可。 Make sure the CSS part is inside your style tag while Angular inside your Script tag.确保 CSS 部分在您的 style 标签内,而 Angular 在您的 Script 标签内。

Happy Coding :)快乐编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM