javascript-framework

Angular JS observe on directive attribute

只谈情不闲聊 提交于 2019-11-30 06:12:07
How can angular js watch attributes on custom directive in order to accept angular values to be bind Here is what I have so far: <tile title="Sleep Duration" data-value="{{sleepHistory.averageSleepTime}}"/> app.directive('tile', [function() { return { restrict: 'E', link: function(scope, element, attrs) { var title = attrs.title; attrs.$observe('dataValue', function(val) { var data = val; console.log(data); var dom = "<div>" + "<p>" + title + "</p>" + "<p>" + data + "</p>" + "</div"; $(element).append($(dom.trim())); }); } }; }]); but the observed value is coming back as undefined From http:/

How to find unique records from two different array in jquery or javascript?

纵饮孤独 提交于 2019-11-30 05:01:23
问题 I want to get unique values from two different arrays. Two arrays are as below in JavaScript: <script> var a=new Array; var b=new Array; a={'a','b','c','d','e'} b={'a','d','e','c'} </script> I want output like: new array => {'a','c','d','e'} How can I find unique records from both arrays using JavaScript prototype function or jQuery function? 回答1: I don't know if you have the terms correct. Unique values to me would be members which appear only once in either array. It seems you want members

How to apply a filter on multiple objects using AngularJS?

▼魔方 西西 提交于 2019-11-30 04:02:14
I have the user object defined as below. $scope.users = [{id: 1, name: 'Adam', friends: [{name: 'John', age: 21, sex: 'M'}, {name: 'Brad', age: 32, sex: 'M'}]}] Then I have the following code: <div ng-repeat="user in users> <input type="text" ng-model="searchText"> <div ng-repeat="friend in user.friends | filter:searchText"> {{user.name}} {{friend.name}} {{friend.age}} </div> </div> Now when I type in the textbox the text: 'searchText', I want the filter to display the name of the user and the name/age of the friend. Can anyone help me with how to do this? If I am correct, then I think that I

AngularJS use a function in a controller to return data from a service to be used in ng-repeat

╄→尐↘猪︶ㄣ 提交于 2019-11-30 03:56:48
问题 I am trying to use a function in a controller to return data so that I can re-use the function across the app to call the data as well as refresh it occasionally. My code appears correct, but in practice, crashes the browser on each load. I am able to get it to work by using an E directive and then placing the element in the partial, but that doesn't accomplish what I need. Ultimately, I would like to do something like this: <div ng-repeat="user in getListUsers()">{{ user.somedata }}</div> I

jQuery equivalent for window.document.write

坚强是说给别人听的谎言 提交于 2019-11-30 03:19:06
问题 Does anyone know the jQuery equivalent for window.document.write('') in javascript? Thanks 回答1: This will add the string "hello" right before the body closing tag. Not exactly the behavior of write , but you can do this to any element to get the content to appear where you want it. $(document.body).append('hello'); Also available are prepend(content) and replaceWith(content) for all your insertion needs! 回答2: First, jQuery is JavaScript, it is just a library of functions to make coding easier

Is plain vanilla JavaScript better than using frameworks like jQuery or MooTools? [closed]

时光毁灭记忆、已成空白 提交于 2019-11-30 02:02:16
I am wondering if it is a good idea to rely on frameworks like jQuery or MooTools or should we just use plain JavaScript? Apart from avoiding the re-invention of wheel, do they add any specific value? Since the frameworks are open to the public, can there be possibility of exploitation of any security holes that might appear (of course, unintentionally :) ) in the frameworks? Are there any other points that are to be considered when choosing a framework or otherwise? Frameworks solve cross-browser bugs which normally would cost hours of your time, so you can focus on functionality instead of

Don't the data attribute options used in Bootstrap, Angular.js, and Ember.js conflict with Unobtrusive Javascript principles? [closed]

邮差的信 提交于 2019-11-29 22:53:12
I've always been told it's good practice (ala 'unobtrusive javascript') separate JavaScript from HTML markup. However, I've been seeing the opposite trend with a number of new and popular frameworks such as Bootstrap, Angular.js, and Ember.js. Can someone tell me why this isn't considered bad practice? Unobtrusive Javascript is a good practice for many places on the web. The frameworks you mentioned are often used for creating full-blown Javascript applications. In many of these apps, the experience without Javascript is often a blank page. In that environment, the value of separating your

Real Time data graph [closed]

落爺英雄遲暮 提交于 2019-11-29 22:51:51
I would like to build a web-based real time data graph and i'm looking at the different options such as: Html5 canvas JS libraries with graph support such as Extjs By real time i mean, either the client polling the web server say every second or using reverse ajax; the server pushes data to the client when available. Can you please recommend any? You may want to consider using Flot , an open-source plotting library based on jQuery . I'm assuming that by real-time you mean that the graph will update automatically. The following is how your code would look like if you were to fetch and plot the

How to set up JavaScript namespace and classes properly?

▼魔方 西西 提交于 2019-11-29 19:52:01
It seems there are so many ways to set up a JavaScript application so it is confusing as to which one is correct or best. Are there any difference to the below techniques or a better way of doing this? MyNamespace.MyClass = { someProperty: 5, anotherProperty: false, init: function () { //do initialization }, someFunction: function () { //do something } }; $(function () { MyNamespace.MyClass.init(); }); Another way: MyNamespace.MyClass = (function () { var someProperty = 5; var anotherProperty = false; var init = function () { //do something }; var someFunction = function () { //do something };

Are there any knockoutjs page/routing frameworks?

旧城冷巷雨未停 提交于 2019-11-29 19:43:48
Coming from asp.net MVC 3. In MVC4 they introduced WebAPI's. It would be nice to be able to do all view/routes code in javascript and just rely on MVC for API. Heck it's really cool that webapi's can be run independent of IIS! That being said: Are there any page frameworks that can leverage KnockoutJS which are similar to my mock-up below: Framework.RegisterRoutes(..,mainViewModel);//sets the CurrentViewModel? Each route being a separate file of a viewModel, and a view to be injected into the master view var mainviewModel= function(){ var self = this; self.CurrentViewModel = ko.observable(); .