我对angularjs比较新.我有一些代码(HTML + JS)允许用户添加和删除范围内数组中的条目.但是现在我正在大量重复不同数组的代码.我知道这可以重新考虑,但我不确定角度方法,除了我可能想要使用指令的事实.任何帮助非常感谢.
HTML
<div class="control-group" ng-class="{error: form.profile.seeking.$invalid}" ng-controller="SeekingCtrl">
<label class="control-label" for="profile.seeking">Seeking</label>
<div class="controls">
<ul ng-repeat="seeks in profile.seeking">
<li>{{seeks}} <button class="btn" ng-click="removeSeeks()">Remove</button></li>
</ul>
<input type="text" ng-model="newseeks" id="profile.seeking">
<button class="btn" ng-disabled="!newseeks" ng-click="addSeeks()">Add new</button>
</div>
Run Code Online (Sandbox Code Playgroud)
<div class="control-group" ng-class="{error: form.project.offering.$invalid}" ng-controller="OfferingCtrl">
<label class="control-label" for="project.offering">Offering</label>
<div class="controls">
<ul ng-repeat="offer in project.offering">
<li>{{offer}} <button class="btn" ng-click="removeOffer()">Remove</button></li>
</ul>
<input type="text" ng-model="newoffer" id="project.offering">
<button class="btn" ng-disabled="!newoffer" ng-click="addOffer()">Add new</button>
</div>
Run Code Online (Sandbox Code Playgroud)
Javascript
var SeekingCtrl = function($scope) {
$scope.addSeeks = function() {
$scope.profile.seeking = $scope.profile.seeking || [];
$scope.profile.seeking.push($scope.newseeks);
$scope.newseeks = …Run Code Online (Sandbox Code Playgroud) 我在使用Angular在我的网站上实现一个简单的推文按钮时遇到问题.我已经做了一些研究,并使用jQuery为AJAX站点找到了一些解决方案,但据我所知,使用解决方案(如下)将涉及在控制器外运行脚本,因此将是非Angular和A Bad Thing.
有没有人以Angular的方式解决这个问题或有任何提示如何?
谢谢.
AJAX解决方案:
//adding button to dom
$('#tweetbutton').append('<a class="twitter-share-button" href="http://twitter.com/share" data-url="http://www.google.nl>Tweet</a>');
//loading widgets
$.getScript('//platform.twitter.com/widgets.js', function(){
//calling method load
twttr.widgets.load();
Run Code Online (Sandbox Code Playgroud)