angularjs-scope

Why doesn't a directive with an isolate scope apply the scope to it's DOM element?

倖福魔咒の 提交于 2019-12-13 08:14:12
问题 I'm trying to figure out how AngularJS scopes work. I'm also curious why they work the way they do. I think the following behavior doesn't make sense (fiddle 1). <div ng-app="app"> <p>outer element's scope: {{$id}}</p> <custom-directive isolate-value="Hello!"> <p>inner element's scope: {{$id}}</p> <p>isolate value: {{isolateValue || 'undefined'}}</p> </custom-directive> </div> function Directive() { return { restrict: 'E', scope: { isolateValue: "@" }, link: function(scope, element,

Put Object in Restangular

喜你入骨 提交于 2019-12-13 08:02:27
问题 You see below my code to change a record from my db using restangular. Restangular.one("/mywebsite/bin/server.fcgi/REST/players", "70").get().then(function(c){ $scope.content = c; }) $scope.content.Name= "Asqan"; $scope.content.put(); when i try to put as the last line of my code, it gives the error: PUT http://localhost/mywebsite/bin/server.fcgi/REST/players 404 (Object not found) ps: no other issue with adding or getting. 回答1: you should do it in the then function, Restangular.one("

Transferring data between non-nested components

隐身守侯 提交于 2019-12-13 07:38:07
问题 Basically , What I desire is to transfer data b/w components. I have one angular2 component on master page for partial view of login - <loginpartial></loginpartial> This is initially rendered through this html template with child component - <ul [hidden]="!item.isAuthenticated"> <li><a href="javascript:;">Hello! {{item.userName}}</a></li> <li><a href="javascript:;">LogOff</a></li> </ul> <ul [hidden]="item.isAuthenticated"> <li><a href="javascript:;">Hello! User</a></li> <li><a href=

Why variable defined in the directive controller not working?

≯℡__Kan透↙ 提交于 2019-12-13 07:16:35
问题 Why i defined 'sayHi' in the controller, and it does not display in the template? js: (function(){ var app = angular.module('myApp', []); app.directive("directive1", function(){ return { restrict : 'E', scope: { }, link : function($scope){ }, controller: ['$scope', function($scope){ $scope.sayHi = 'hi'; window.console.log($scope.sayHi); }] }; }); })(); html: <div style="border: 1px solid; padding: 10px; min-height: 100px;"> Directive1 : <directive1> {{sayHi}} </directive1> </div> detail plnkr

Safe and correct way to reload data on angularjs ($timeout)

為{幸葍}努か 提交于 2019-12-13 07:13:11
问题 I use this code to safe work with $timeout : $scope.intervalFunction = function () { setTimeout(function () { //DO console.log('refresh'); if ($scope.currentNode) { $scope.intervalFunction(); } }, 5000) }; function setTimeout(fn, delay) { var promise = $timeout(fn, delay); var deregister = $scope.$on('$destroy', function () { $timeout.cancel(promise); }); promise.then(deregister); } $scope.intervalFunction(); it is correct? 回答1: There are a few optimizations here, if it is always the same

How to access an array in AngularJS controller populated by $resource get()?

為{幸葍}努か 提交于 2019-12-13 07:05:45
问题 I can not access an array in the AngularJS controller but it works in the view. In the controller: .results returns undefined function TwitterCtrl($scope, $resource){ $scope.twitter = $resource('http://search.twitter.com/:action', {action:'search.json', q:'angularjs', callback:'JSON_CALLBACK'}, {get:{method:'JSONP', params: {rpp: 4}}}); $scope.twitterResult = $scope.twitter.get({q:"example"}); //returns the resource object console.log($scope.twitterResult) //returns undefined console.log(

How to dynamically bind function to ng-click using the function expression from model

自古美人都是妖i 提交于 2019-12-13 06:59:57
问题 I have the following element in my Angular template to generate a button bar with Font Awesome icons: <li data-ng-repeat="btn in navigation.buttonBar" data-ng-click="{{ btn[1] }}" class="btn btn-default" style="font-size: 30px; vertical-align: middle;" tooltip-placement="bottom" tooltip="{{ btn[2] }}"> <i class="fa {{ btn[0] }}"></i> </li> navigation.buttonBar is the following array of arrays: [ [ "fa-minus", "less()", "Show fewer cloud buttons." ], [ "fa-plus", "more()", "Show more cloud

ANGULARJS - $scope does not apply the first time I call my async method

南楼画角 提交于 2019-12-13 06:55:24
问题 I have a problem with my angularjs controller. It goes like this I am triggering an async method on button click, this method shows a dialog with an input text, once you close the dialog, that text is added to a scope array, However, the first time I execute the async method the view does not reflect the changes in the scope, if I click a second time and the function gets called again then I can see all the changes in my view (including the first change I made and didn't see immediately) Here

How to retain the last opened accordion in a group by invoking function in is-open attribute

眉间皱痕 提交于 2019-12-13 06:53:20
问题 I'm having accordion which is populated dynamically. <accordion-group ng-repeat="data in dataList" is-open="isAccordionOpen(data.dataName)"> <accordion-heading> <span ng-click="openedAccordionGroup(data.dataName)" class="accordionSpan"><b>{{data.dataName}}</b> </span> </accordion-heading> </accordion-group> Here dataList keep on changing after 15 sec that means I'm populate dataList after regular inteval of 15sec. So i need to persist the last opened accordion group. DataList can be very hude

My view scope data is not updated

感情迁移 提交于 2019-12-13 06:49:54
问题 I have an simple AngularJS application with a service holding a collection. There is a navigation view with a form and its controller adding to the collection. The view in included with an ng-include attribute in the index.html file: <div ng-include="'views/nav.html'"></div><div ng-view=""> There is also another view and its controller to display the collection content. This view is called in with a route statement in the app/scripts/app.js file: .when('/link/list/', { templateUrl: 'scripts