Custom Angular Dart Component Package - dart

I have an angular dart component I created that I am trying to use in my main project. I am using path packages to reference it. The component's constructor (in the dart file) is being called, but I get errors that the .css and .html file cannot be found. The paths it is looking for them in seem to exist, so I'm not sure why it cannot find them.
I have other custom components I am using throughout my code, but there is no html or css files associated with them and they were fine, it seems to be limited to the html and css files.
Here are snippets of my code
test.dart located in test_component/lib/test_component/
library TestCom;
import 'package:angular/angular.dart';
#Component(
selector: 'tester',
templateUrl: 'test.html',
cssUrl: 'test.css')
class TestComponent {
String t = "this is the test component";
TestComponent() {
print("Test Component STARTED");
}
}
test.html located in test_component/lib/test_component/
<h3>{{t}}</h3>
pubspec.yaml located in test_component
name: TestModule
dependencies:
angular: "^1.1.2+2"
browser: any
transformers:
- angular:
html_files:
- lib/test_component/test.html
main.dart located in main/src/main/dart/web
import 'package:TestModule/test_component/test.dart';
class MyAppModule extends Module {
MyAppModule() {
bind(TestComponent);
}
}
index.html located in main/src/main/dart/web/
<tester></tester>
pubspec.yaml located in main/src/main/dart
name: main_package
dependencies:
angular: "^1.1.2+2"
browser: any
shadow_dom: any
json_object: any
bootjack: any
crypto: any
xml: "^2.3.2"
TestModule:
path: ../../../../test_component
transformers:
- angular:
After I run pub get, in the packages folder of my main project, TestModule/test_component/ exists with test.css, test.dart, and test.html in it. I'm not sure why when I run it, it can not find the .html and .css files.
This is what is displayed in the console when I run it
Observatory listening at http://127.0.0.1:54254/
Test Component STARTED
index.html:1 GET http://127.0.0.1:3030/packages/TestModule/test_component/test.css 404 (Not Found)
index.html:1 GET http://127.0.0.1:3030/packages/TestModule/test_component/test.html 404 (Not Found)
2 HTTP 404: <html><head><title>404 Not Found</title></head><body>File not found</body></html>
STACKTRACE:
null

Try this
name: TestModule
dependencies:
angular: "^1.1.2+2"
browser: any
transformers:
- angular:
html_files:
- packages/TestModule/test_component/test.html
For the css file however, I think you only need to put them into the same folder as the component's Dart file.

Related

Angular 4 templateUrl file not found

I am using Angular 4.1.3 with Rails 5.1
I am trying to implement the app component and if I use template and write my html, everything works, but I want to use templateUrl.
Here is my component.
import { Component } from '#angular/core';
#Component({
selector: 'app',
templateUrl: './app.component.html'
})
export class AppComponent {}
And this is my file structure
├── app
| ├── app.component.html
| └── app.component.ts
| └── app.module.ts
I understand that in the #Component you can add moduleId: module.id but I thought this is no longer needed in angular 4.1.3.
If I do add it, it tells me:
moduleId should be a string in "AppComponent"
I also thought that if you do not include the moduleId angular just grabs from root directory, but if I do an absolute path, it should work right?
If you guys could help, that would be awesome.
I am assuming you're using the new webpacker-gem in your rails project!
There is a description of how to use templateUrl with it here in the documentation: Use HTML templates with Typescript and Angular
If you would like to keep templateUrl you could use angular2-template-loader webpack plugin:
# add plugins to project
yarn add angular2-template-loader raw-loader
and configure it:
# edit config/webpack/loaders/angular.js with
module.exports = {
test: /.ts$/,
loaders: ['ts-loader', 'angular2-template-loader'],
exclude: [/\.(spec|e2e)\.ts$/]
}
# create a new loader for htmls config/webpack/loaders/html.js
module.exports = {
test: /\.(html)$/,
loader: 'raw-loader',
exclude: /\.async\.(html)$/
}

Polymer-dart: http://www.xxx/index.bootstrap.initialize.dart Failed to load resource - where is it?

I have a Dart (1_16_0_dev_2) Polymer web app. I see >the problem here< , but I still have it. My yaml is :
dependencies:
browser: ^0.10.0
polymer: ^1.0.0-rc.16
polymer_elements: ^1.0.0-rc.8
transformers:
- polymer:
entry_points:
- web/index.html
- $dart2js:
$include: '**/*.bootstrap.initialize.dart' (I've tried with and without this line)
minify: true
commandLineOptions:
- --trust-type-annotations
- --trust-primitives
I've tried without the dart2js too. I can view my website in (some!?) Chromes on different devices, but Dartium gives this complaint
http://www.xxx/index.bootstrap.initialize.dart Failed to load resource: the server responded with a status of 404 (Not Found)
(and I assume it's why FireFox and Edge show a blank page).
What am I doing wrong please?
Thanks,
cheers,
s
I was missing:
<script src="packages/web_components/webcomponents-lite.min.js"></script>
in index.html. Now it works in Firefox, and Dartium isn't looking for the bootstrap file.

pub serve not finding files under lib

I'm testing with the developer preview of Angular Version 2 and serving it up using pub serve
I would like to estalblish a convention to structure my files inside /lib/ as follows:
└── project/lib/root
├── root.css
├── root.dart
└── root.html
└── project/web/
├── index.html
└── index.dart
In my /web/index.dart file i am successfully able to initialize the #View and #Component from root.dart
However, when i preview in Dartium via pub serve - i can't seem to serve up /lib/root/root.html
#Component(
selector: 'jroot'
)
#View(
templateUrl: '../../lib/root/root.html',
directives: const [If]
)
class Root {
String content = 'Root - This is the entry point to the component';
List<Times> list;
Root(){
print('RootComponent Init');
}
}
Dartium Console:
GET http://localhost:8080/lib/root/root.html 404 (Not Found)
I've been reading the documents for polymer here which states:
"Non-Dart files under lib must use relative paths to import assets under lib:"
https://www.dartlang.org/polymer/app-directories.html
<!-- lib/a5/a6/a6.html imports lib/a4.html -->
<link rel="import" href="../../a4.html">
Running a python simple web server seems to work, so the problems is with pub serve:
python -m SimpleHTTPServer
Question: How do a configure pub serve to work with nested html files from the lib folder?
Ensure you have the proper entry points on your pubspec.yaml transformers:
name: 'project'
version: 0.0.1
dependencies:
angular2: '2.0.0-alpha.23'
browser: any
transformers:
- angular2:
entry_points:
- web/index.dart //this
reflection_entry_points:
- web/index.dart //this
Then I think this should work
templateUrl: 'packages/project/root/root.html',
or just
templateUrl: 'root.html',

relative path doesn't work with paths

I'm having a problem with relative paths in requirejs.
First of all, I have the following structure. I'm running it with a virtual host (os.com) and the path is os.com/test
index.html
<script data-main="config" src="require.js"></script>
config.js
require.config({
baseUrl: "./apps",
deps: ['ui'],
paths: {
ui: 'ui/ui',
system: 'system/system',
core: 'core/core'
}
});
ui.js
define(['./class/menuBuilder',"./class/window"], function(menuBuilder, windowBuilder){
return {
menuBuilder: menuBuilder,
windowBuilder: windowBuilder
}
});
When I run it, I get the following errors.
GET http://os.com/test/apps/class/menuBuilder.js 404 (Not Found)
GET http://os.com/test/apps/class/window.js 404 (Not Found)
If I take out 'ui' property from the 'paths' property then change deps to ['ui/ui'], it works, but I would like to use paths.
Changed config.js
require.config({
baseUrl: "./apps",
deps: ['ui/ui'],
paths: {
system: 'system/system',
core: 'core/core'
}
});
How do I change my config to make paths and relative path work together?
I had similar problem. I didn't have deps:'ui' part in my configuration, just the path setting, but still the relative module reference ('./class/menuBuilder') would not work from the module loaded with path ("ui: 'ui/ui'") and would use baseUrl instead. To solve it, I defined 'ui' as a package:
require.config({
baseUrl: "./apps",
deps: ['ui'],
paths: {
system: 'system/system',
core: 'core/core'
},
packages : [
{
name: 'ui',
location : 'ui',
main : 'ui'
},
]
});
In this case require will load relatively-pathed modules correctly.
Here is a useful post: Relative paths with RequireJS modules/packages
The solution here is to use map configuration, not paths configuration. Paths configurations should only be used for folders, not modules themselves. Map configurations apply to individual modules.
So try:
require.config({
map: {
'*': {
'ui': 'ui/ui'
}
}
});

dajax.core ImportError at /No module named

I've installed dajaxice by this tutorial:
Copied folder "dajaxice" (from archive) to project folder.
Added all changes to setting.py & urls.py
Added next lines to template:
{% load dajaxice_templatetags %}
{% dajaxice_js_import %}
Created ajax.py in the project folder
Code from ajax.py:
from django.utils import simplejson
from dajaxice.core import dajaxice_functions
#dajaxice_register
def example1(request):
return simplejson.dumps({'message': 'hello world'})
dajaxice_functions.register(example1)
Code from .js file:
$("#id_submit").click(function(){
Dajaxice.theproject.example1(callback_example);
console.log("test clicked");
return false; });
When I restart the project in browser at first request I got:
ImportError at / No module named dajax.core
Request Method: GET
Request URL: http:// 127.0.0.1:8000/
Django Version: 1.4
Exception Type: ImportError
Exception Value: No module named dajax.core
Exception Location: C:\Python27\lib\importlib\__init__.py in import_module, line 37
Python Executable: C:\Python27\python.exe
Python Version: 2.7.3
Python Path: ['E:\\Projects\\py\\sites\\theproject', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL']
Server time: Fri, 3 Aug 2012 14:50:03 +0300
Any ideas?
load ajax.py in init.py(of main app)
Dajaxice is updating all the time. Make sure you have downloaded and installed the correct version of Dajax for the document you are reading. In your error message, it says, "No module named dajax.core", which is probably because you are using the wrong version.
And the current version of Dajaxice and Dajax can be found here:
https://pypi.python.org/pypi/django-dajax
https://pypi.python.org/pypi/django-dajaxice/0.5.5

Resources